File tree Expand file tree Collapse file tree
main/java/com/ocpsoft/pretty/faces/url
test/java/com/ocpsoft/pretty/faces/url Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ public String buildURLFromSegments(final List<String> segments)
5555 }
5656 }
5757
58- if (hasTrailingSlash () && ! result . toString (). endsWith ( "/" ) )
58+ if (hasTrailingSlash ())
5959 {
6060 result .append ("/" );
6161 }
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ public class URL
3333
3434 private final Map <String , List <String >> decodedSegments = new HashMap <String , List <String >>();
3535 private static final Pattern SLASH_PATTERN = Pattern .compile ("/" , Pattern .LITERAL );
36+ private static final int NEGATIVE_PATTERN_LIMIT = -1 ;
3637
3738 /**
3839 * Create a URL object for the given url String. The input string must not yet have been decoded.
@@ -54,7 +55,7 @@ public URL(final String url)
5455 }
5556
5657 String trimmedUrl = trimSurroundingSlashes (url );
57- String [] segments = SLASH_PATTERN .split (trimmedUrl );
58+ String [] segments = SLASH_PATTERN .split (trimmedUrl , NEGATIVE_PATTERN_LIMIT );
5859
5960 this .segments = Arrays .asList (segments );
6061 }
Original file line number Diff line number Diff line change 2323
2424public class URLTest
2525{
26+
27+ @ Test
28+ public void testURLWithEmptySegmentsConstruction () throws Exception
29+ {
30+ final String URL_WITH_TRAILING_EMPTY_SEGMENT = "/test//" ;
31+ final String URL_WITH_LEADING_EMPTY_SEGMENT = "//test/" ;
32+ final String URL_WITH_LEADING_AND_TRAILING_EMPTY_SEGMENTS = "//test//" ;
33+
34+ assertEquals (URL_WITH_TRAILING_EMPTY_SEGMENT ,
35+ new URL (URL_WITH_TRAILING_EMPTY_SEGMENT ).decode ().toURL ());
36+ assertEquals (URL_WITH_LEADING_EMPTY_SEGMENT ,
37+ new URL (URL_WITH_LEADING_EMPTY_SEGMENT ).decode ().toURL ());
38+ assertEquals (URL_WITH_LEADING_AND_TRAILING_EMPTY_SEGMENTS ,
39+ new URL (URL_WITH_LEADING_AND_TRAILING_EMPTY_SEGMENTS ).decode ().toURL ());
40+ }
41+
2642 @ Test
2743 public void testURLPreservesOriginalURL () throws Exception
2844 {
You can’t perform that action at this time.
0 commit comments