Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Stanimir Stamenkov Newsgroups: comp.lang.java.programmer Subject: Re: [LONG] java.net.URI encoding weirdness Date: Tue, 06 May 2014 22:24:13 +0300 Organization: A noiseless patient Spider Lines: 62 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 6 May 2014 19:24:12 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="daaaf033c96883e83e80378381c6380d"; logging-data="32680"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+pnx+YkU+yH3V88PYNh4/6" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0 SeaMonkey/2.26 In-Reply-To: X-Face: "@)%Vlap6d%OVYDS}B4YUWE@yUy+^!w/+.q.,c5kjI#+uG?kYP&r/pTjNWgo:g[A,O=AL3/ j&4Le2cau$ > Doesn't each % above indicate an encoded value, or are you referring > to something else? You're missing I'm using further: URI v = new URI(u.getScheme(), u.getUserInfo(), "server2", u.getPort(), u.getPath(), u.getQuery(), u.getFragment()); The 'query' property value is already decoded. > I'm not sure we're not talking cross purposes here. > > URI u = URI.create( decode("http://server1/path" > + "?param%3D1=value%261¶m%3F2=value%242" > + "#fragment")); > System.out.println(u.toASCIIString()); > > run: > http://server1/path?param=1=value&1¶m?2=value$2#fragment > BUILD SUCCESSFUL (total time: 1 second) The URI.create(String) and the URI(String) constructor perform complete parsing, and they are working fine. Note, after decoding the result of your example is already wrong, different from the original URI: http://server1/path?param%3D1=value%261¶m%3F2=value%242#fragment There are two parameters (decoded names): param=1 param?2 and their (decoded) values are: value&1 value#2 What would be the query parameters in your result: http://server1/path?param=1=value&1¶m?2=value$2#fragment ? -- Stanimir