saokar / urlrewritefilter

Automatically exported from code.google.com/p/urlrewritefilter
Other
0 stars 0 forks source link

org.tuckey.web.filters.urlrewrite.utils.URLEncoder ampersand encoded incorrectly #97

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. System.out.println("encodedPath"+ URLEncoder.encodePathSegment("Events & 
Programs", "UTF-8"));
2.
3.

What is the expected output? What do you see instead?
Expected "Events%20%26%20Programs" (no quotes)
Instead see "Events%20&%20Programs"

What version of the product are you using? On what operating system?
r307 checkin

Please provide any additional information below.
Thank you for your otherwise excellent code. You may want to alter 
URLDecodingTest to use org.tuckey.web.filters.urlrewrite.utils.URLEncoder 
instead of java.net.URLEncoder, and here is another test case:

Add to URLDecodingTest.java:
    @Test
    public void testPathAmpersandEncoding() throws UnsupportedEncodingException {
        String path = "Events & Programs";
        String encodedPath = org.tuckey.web.filters.urlrewrite.utils.URLEncoder.encodePathSegment(path, "UTF-8");
        assertEquals(encodedPath, "Events%20&%20Programs");
    }

Original issue reported on code.google.com by EdgeWise...@gmail.com on 25 Oct 2011 at 9:07

GoogleCodeExporter commented 9 years ago
The function you are referring to is creating a path segment. & should 
definitely not be encoded as & 

java.net.URLEncoder can be used for encoding the query string

org.tuckey.web.filters.urlrewrite.utils.URLEncoder handles individual path 
parts and path segments.

See 
http://www.lunatech-research.com/archives/2009/02/03/what-every-web-developer-mu
st-know-about-url-encoding

Original comment by jontro@gmail.com on 1 Nov 2011 at 5:44