Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #28400
| From | markspace <markspace@nospam.nospam> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: [LONG] java.net.URI encoding weirdness |
| Date | 2014-05-06 12:24 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <lkbctv$dg$1@dont-email.me> (permalink) |
| References | (1 earlier) <lk8n0o$ibf$1@dont-email.me> <lk8u3d$agp$1@dont-email.me> <lk9861$dk5$1@dont-email.me> <lka2s0$kma$1@dont-email.me> <lkb5rt$83i$1@dont-email.me> |
On 5/6/2014 10:24 AM, markspace wrote:
> On 5/6/2014 12:26 AM, Stanimir Stamenkov wrote:
>
>> public static void main(String[] args) throws Exception {
>> URI u = URI.create("http://server1/path"
>> + "?param%3D1=value%261¶m%3F2=value%232"
>> + "#fragment");
>
>> Note how the 'query' is wrong now.
OK, I think I see what is going on. Most of your OP was frankly wrong,
however this one represents an actual bug in the URI parsing:
public class URITest3 {
public static void main(String[] args) throws Exception {
URI u = URI.create("http://server1/path"
+ "?param%3D1=value%261¶m%3F2=value%232"
+ "#fragment");
System.out.println(u.toASCIIString());
URI v = new URI(u.getScheme(),
u.getUserInfo(),
"server2",
u.getPort(),
u.getPath(),
u.getQuery(),
u.getFragment());
System.out.println(v.toASCIIString());
// "raw" is user error, omitted.
}
Output:
http://server1/path?param%3D1=value%261¶m%3F2=value%232#fragment
http://server2/path?param=1=value&1¶m?2=value%232#fragment
Yes clearly the query part was not parsed correctly. It's ambiguous and
can't be parsed. (Incidentally, '=' and '&' weren't parsed correctly,
but I think '?' was, and was incorrectly escaped in your original
string. Double check with the spec on that.)
To fix this, Oracle should at minimum deprecate this ctor. It's plainly
broken.
Oracle should consider replacing it with a ctor that allows the query to
be parsed correctly:
public URI( String scheme, String userInfo, String host,
int port, String path, String fragment,
String[] ... paramValue ) ...
where paramValue is a vararg of pairs of strings which can be then
parsed and assembled correctly
new URI( ...,
{"param=1","value&1"},{"param?2","value#2"} );
However this is getting a bit complicated, so I think Oracle should
consider adding a builder class to build URIs a little more
conveniently. They should consider adding both parsed (like URI's
current multi-argument ctors) and raw (already quoted) for easy
"matching" of existing URIs. I think they should also make public some
parts of the Parse (currently an private class inside URI) and make at
least the various quoting methods available to developers, URLEncoder
looks ill-suited for this purpose.
public class URI {
public static quoteScheme( .. ){...
public static quoteUserInfo( .. ){...
public static quoteHost( .. ){...
public static quotePath( .. ){...
... etc.
public class Builder {
public Builder() {...
public Builder setScheme(...
public Builder setHost(...
public Builder setPath(...
public Builder setRawPath(...
public Builder addParameter( String param, String value )..
public Builder changeParameter( String param, String value )..
public Builder addRawParameter( String paramValue)..
public Builder setFragment(...
public Builder setRawFragment(...
public Builder clearParams()...
public Builder clearAll()...
... etc. as needed
You should double check your test cases and then submit a bug report to
the OpenJDK project (I have better luck communicating with them than
Oracle's bug reports page). That's about the best I can do right now.
To fix an immediate problem, I'm pretty sure all your other test cases
were wrong, so you should use test case 3 above as a template and you'll
have to deal with parsing the query string yourself, unfortunately.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[LONG] java.net.URI encoding weirdness Stanimir Stamenkov <s7an10@netscape.net> - 2014-05-05 16:11 +0300
Re: [LONG] java.net.URI encoding weirdness Mike Amling <mamling@chaff.us> - 2014-05-05 11:37 -0500
Re: [LONG] java.net.URI encoding weirdness Mike Amling <mamling@chaff.us> - 2014-05-05 11:43 -0500
Re: [LONG] java.net.URI encoding weirdness Stanimir Stamenkov <s7an10@netscape.net> - 2014-05-05 19:50 +0300
Re: [LONG] java.net.URI encoding weirdness markspace <markspace@nospam.nospam> - 2014-05-05 11:58 -0700
Re: [LONG] java.net.URI encoding weirdness Stanimir Stamenkov <s7an10@netscape.net> - 2014-05-05 23:59 +0300
Re: [LONG] java.net.URI encoding weirdness markspace <markspace@nospam.nospam> - 2014-05-05 16:51 -0700
Re: [LONG] java.net.URI encoding weirdness Stanimir Stamenkov <s7an10@netscape.net> - 2014-05-06 10:26 +0300
Re: [LONG] java.net.URI encoding weirdness Steven Simpson <ss@domain.invalid> - 2014-05-06 08:47 +0100
Re: [LONG] java.net.URI encoding weirdness Stanimir Stamenkov <s7an10@netscape.net> - 2014-05-06 11:02 +0300
Re: [LONG] java.net.URI encoding weirdness markspace <markspace@nospam.nospam> - 2014-05-06 10:24 -0700
Re: [LONG] java.net.URI encoding weirdness Stanimir Stamenkov <s7an10@netscape.net> - 2014-05-06 22:24 +0300
Re: [LONG] java.net.URI encoding weirdness markspace <markspace@nospam.nospam> - 2014-05-06 12:24 -0700
Re: [LONG] java.net.URI encoding weirdness Stanimir Stamenkov <s7an10@netscape.net> - 2014-05-06 22:34 +0300
Re: [LONG] java.net.URI encoding weirdness markspace <markspace@nospam.nospam> - 2014-05-06 13:04 -0700
Re: [LONG] java.net.URI encoding weirdness Stanimir Stamenkov <s7an10@netscape.net> - 2014-05-06 23:07 +0300
Re: [LONG] java.net.URI encoding weirdness Stanimir Stamenkov <s7an10@netscape.net> - 2014-05-06 23:04 +0300
Re: [LONG] java.net.URI encoding weirdness Steven Simpson <ss@domain.invalid> - 2014-05-06 20:29 +0100
Re: [LONG] java.net.URI encoding weirdness markspace <markspace@nospam.nospam> - 2014-05-06 13:01 -0700
csiph-web