Skip to content

Commit 95e4c33

Browse files
committed
Fixed encoding for square brackets and less/greater than characters
1 parent 08e7890 commit 95e4c33

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

  • core/src

‎core/src/main/java/com/ocpsoft/pretty/faces/url/URL.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,14 @@ private static String decodeSegment(final String segment)
143143
{
144144
try
145145
{
146-
final URI uri = new URI(("http://localhost/" + segment).replace(" ", "%20").replace("\"", "%22"));
146+
final URI uri = new URI(("http://localhost/" + segment)
147+
.replace(" ", "%20")
148+
.replace("\"", "%22")
149+
.replace("[", "%5B")
150+
.replace("]", "%5D")
151+
.replace("<", "%3C")
152+
.replace(">", "%3E")
153+
);
147154
return uri.getPath().substring(1);
148155
}
149156
catch (URISyntaxException e)

‎core/src/test/java/com/ocpsoft/pretty/faces/url/URLTest.java‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,35 @@ public void testQuoteCharacterEncodingAndDecoding() throws Exception
140140
assertEquals("/a\"b", new URL("/a\"b").decode().toURL());
141141

142142
}
143-
143+
144+
@Test
145+
public void testSquareBracketEncodingAndDecoding() throws Exception
146+
{
147+
148+
// encode
149+
assertEquals("/%5Ba%5D", new URL("/[a]").encode().toURL());
150+
151+
// decode
152+
assertEquals("/[a]", new URL("/%5Ba%5D").decode().toURL());
153+
154+
// decode of not-encoded character
155+
assertEquals("/[a]", new URL("/[a]").decode().toURL());
156+
157+
}
158+
159+
@Test
160+
public void testLessGreaterThanEncodingAndDecoding() throws Exception
161+
{
162+
163+
// encode
164+
assertEquals("/%3Ca%3E", new URL("/<a>").encode().toURL());
165+
166+
// decode
167+
assertEquals("/<a>", new URL("/%3Ca%3E").decode().toURL());
168+
169+
// decode of not-encoded character
170+
assertEquals("/<a>", new URL("/<a>").decode().toURL());
171+
172+
}
173+
144174
}

0 commit comments

Comments
 (0)