Created
August 2, 2011 20:40
-
-
Save ryankennedy/1121167 to your computer and use it in GitHub Desktop.
bite me, java.net.URI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# WTF is java.net.URI thinking? | |
# | |
scala> new URI("http", null, "hostname", 80, "/foo", "bar%20is=baz", null) | |
res5: java.net.URI = http://hostname:80/foo?bar%2520is=baz | |
# | |
# Oh, I see...I have to do this the inconvenient way. | |
# | |
scala> URI.create("http://hostname:80/foo?bar%20is=baz") | |
res6: java.net.URI = http://hostname:80/foo?bar%20is=baz |
Query strings are, by definition, already encoded. What java.net.URI is expecting is some half-encoded query string. For instance, you'll notice that it doesn't encode the ampersand in the query string even though it's entirely possible that I didn't mean it to be a delimiter. If you're going to call a thing a query string, then it should already be encoded. Otherwise the inconsistencies in how it does or does not encode will (as I've demonstrated) bite you in the ass.
In my case, I'm taking HttpServletRequest.getQueryString() and passing it in directly (I'm proxying a call). java.net.URI is being a prick and is re-encoding things that are already percent encoded.
Ryan
… ---
From: spullara ***@***.***
To: ***@***.***
Sent: Tuesday, August 2, 2011 1:44 PM
Subject: Re: gist gist: 1121167
new URI("http", null, "hostname", 80, "/foo", "bar is=baz", null)? why encode the qps first?
http://hostname:80/foo?bar%20is=baz
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1121167
yeah, seems broken to me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
new URI("http", null, "hostname", 80, "/foo", "bar is=baz", null)? why encode the qps first?
http://hostname:80/foo?bar%20is=baz