File tree 4 files changed +34
-14
lines changed
main/java/io/dinject/javalin/generator
test/java/io/dinject/javalin/generator 4 files changed +34
-14
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ String getPath() {
84
84
if (path == null ) {
85
85
return null ;
86
86
}
87
- return Util .trimTrailingSlash (path .value ());
87
+ return Util .trimPath (path .value ());
88
88
}
89
89
90
90
void addImportType (String rawType ) {
Original file line number Diff line number Diff line change @@ -18,16 +18,21 @@ static PathSegments parse(String fullPath) {
18
18
19
19
StringBuilder path = new StringBuilder ();
20
20
21
- for (String section : fullPath .split ("/" )) {
22
- if (!section .isEmpty ()) {
23
- path .append ("/" );
24
- if (section .startsWith (":" )) {
25
- Segment segment = createSegment (section .substring (1 ));
26
- segments .add (segment );
27
- path .append (segment .path (section ));
28
-
29
- } else {
30
- path .append (section );
21
+ if ("/" .equals (fullPath )) {
22
+ path .append ("/" );
23
+
24
+ } else {
25
+ for (String section : fullPath .split ("/" )) {
26
+ if (!section .isEmpty ()) {
27
+ path .append ("/" );
28
+ if (section .startsWith (":" )) {
29
+ Segment segment = createSegment (section .substring (1 ));
30
+ segments .add (segment );
31
+ path .append (segment .path (section ));
32
+
33
+ } else {
34
+ path .append (section );
35
+ }
31
36
}
32
37
}
33
38
}
Original file line number Diff line number Diff line change 5
5
import javax .lang .model .element .Element ;
6
6
import javax .lang .model .type .DeclaredType ;
7
7
import java .util .ArrayList ;
8
- import java .util .LinkedHashSet ;
9
8
import java .util .List ;
10
- import java .util .Set ;
11
9
12
10
class Util {
13
11
14
- static String trimTrailingSlash (String value ) {
12
+ static String trimPath (String value ) {
13
+ return value .length () <= 1 ? value : trimTrailingSlash (value );
14
+ }
15
+
16
+ private static String trimTrailingSlash (String value ) {
15
17
if (value .endsWith ("/" )) {
16
18
return value .substring (0 , value .length () - 1 );
17
19
}
Original file line number Diff line number Diff line change @@ -26,6 +26,19 @@ public void combinePath() {
26
26
assertEquals (Util .combinePath ("/a" , "/" ), "/a" );
27
27
}
28
28
29
+ @ Test
30
+ public void combinePath_forRoot () {
31
+ assertEquals (Util .combinePath ("/" , "" ), "/" );
32
+ assertEquals (Util .combinePath ("" , "/" ), "" );
33
+ }
34
+
35
+ @ Test
36
+ public void trimPath () {
37
+ assertEquals (Util .trimPath ("/" ), "/" );
38
+ assertEquals (Util .trimPath ("/foo" ), "/foo" );
39
+ assertEquals (Util .trimPath ("/foo/" ), "/foo" );
40
+ }
41
+
29
42
@ Test
30
43
public void snakeCase () {
31
44
You can’t perform that action at this time.
0 commit comments