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 @@ -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 )
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments