File tree Expand file tree Collapse file tree 4 files changed +34
-14
lines changed
main/java/io/dinject/javalin/generator
test/java/io/dinject/javalin/generator Expand file tree Collapse file tree 4 files changed +34
-14
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ String getPath() {
8484 if (path == null ) {
8585 return null ;
8686 }
87- return Util .trimTrailingSlash (path .value ());
87+ return Util .trimPath (path .value ());
8888 }
8989
9090 void addImportType (String rawType ) {
Original file line number Diff line number Diff line change @@ -18,16 +18,21 @@ static PathSegments parse(String fullPath) {
1818
1919 StringBuilder path = new StringBuilder ();
2020
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+ }
3136 }
3237 }
3338 }
Original file line number Diff line number Diff line change 55import javax .lang .model .element .Element ;
66import javax .lang .model .type .DeclaredType ;
77import java .util .ArrayList ;
8- import java .util .LinkedHashSet ;
98import java .util .List ;
10- import java .util .Set ;
119
1210class Util {
1311
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 ) {
1517 if (value .endsWith ("/" )) {
1618 return value .substring (0 , value .length () - 1 );
1719 }
Original file line number Diff line number Diff line change @@ -26,6 +26,19 @@ public void combinePath() {
2626 assertEquals (Util .combinePath ("/a" , "/" ), "/a" );
2727 }
2828
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+
2942 @ Test
3043 public void snakeCase () {
3144
You can’t perform that action at this time.
0 commit comments