RFR: JDK-8022748 (new URI(u.toString()).equals(u), does not hold with paths containing colons
Sebastian Sickelmann
sebastian.sickelmann at gmx.de
Thu Sep 17 03:56:33 UTC 2015
Hi,
is there someone how wants to support me by making a patch for
JDK-8022748[1]
be available for review on cr.openjdk.net?
I placed my webrev here:
https://dl.dropboxusercontent.com/u/43692695/oss-patches/openjdk/JDK-8022748_0/webrev.zip
Thanks
Sebastian
Am 10.09.2015 um 07:41 schrieb Sebastian Sickelmann:
> Hi,
>
> i investigated the problem described in JDK-8022748[1] i found that we
> need to rescue the parser for confusion while parsing relative URIs.
> A URI created through the relativize-method is schemaless and so it
> need to handle the special-case (a colon in the path-element). While
> there is another way to handle this (encode the colon as %3A) i think
> we should not choose that solution. First it would introduce another
> style of special-case handling of a colon in the path (see the method
> maybeAddLeadingDot which is used while normalizing) and when
> resolving it back we would need to decode it back or leave it the
> encoded way which is not suggest by RFC2396 section
> "1.5 URI Transcribability". Also in Section 5 of RFC2396 it is suggested
> to rescue a colon in the path-element in a relative URI through
> prepending a "./" just like in maybeAddLeadingDot.
>
> As i am not an author, but i am a contributer who signed the OCA,
> and I learned in the last days that a patch must come through openjdk
> infrastructure, i am sorry that I need to embed my suggested patch
> below and does not come as a webrev hosted on my dropbox which
> i would normaly do. It would be nice if someone would sponsor this,
> by hosting this for further review on cr.openjdk.java.net or by doing
> the needed discussion/adaption work prio applying it.
>
> -- Sebastian
> [1] https://bugs.openjdk.java.net/browse/JDK-8022748
>
>
>
> diff -r e26938360e58 src/java.base/share/classes/java/net/URI.java
> --- a/src/java.base/share/classes/java/net/URI.java Thu Sep 03
> 14:24:44 2015 -0700
> +++ b/src/java.base/share/classes/java/net/URI.java Thu Sep 10
> 07:19:53 2015 +0200
> @@ -2144,9 +2144,16 @@
> }
>
> URI v = new URI();
> - v.path = cp.substring(bp.length());
> v.query = child.query;
> v.fragment = child.fragment;
> +
> + // While relativizing we loose the schema part of the URI.
> + // As mentioned in section 5 of RFC 2396 we must prepend
> + // relative URI containing a colon with a "./" to not
> + // confuse parsing.
> + v.path = (cp.indexOf(":") >= bp.length() ? "./" : "")
> + + cp.substring(bp.length());
> +
> return v;
> }
>
> diff -r e26938360e58 test/java/net/URI/Relativize.java
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/test/java/net/URI/Relativize.java Thu Sep 10 07:33:44 2015 +0200
> @@ -0,0 +1,41 @@
> +/*
> + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
> + *
> + * This code is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License version 2 only, as
> + * published by the Free Software Foundation.
> + *
> + * This code is distributed in the hope that it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
> + * version 2 for more details (a copy is included in the LICENSE file that
> + * accompanied this code).
> + *
> + * You should have received a copy of the GNU General Public License
> version
> + * 2 along with this work; if not, write to the Free Software Foundation,
> + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
> + *
> + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
> + * or visit www.oracle.com if you need additional information or have any
> + * questions.
> + */
> +/**
> + * @test
> + * @bug 8022748
> + * @summary new URI(u.toString()).equals(u) does not hold with paths
> containing colons
> + */
> +
> +import java.net.URI;
> +import java.net.URISyntaxException;
> +
> +public class Relativize {
> + public static void main(String[] args) throws URISyntaxException {
> + URI orig = new URI(null, null, "/a:b" , null);
> + URI u = new URI( "." ).relativize(orig);
> + if (!new URI(u.toString()).equals(u)) {
> + throw new RuntimeException("Test failed");
> + }
> + System.out.println("Test succeed");
> + }
> +}
>
>
>
>
More information about the net-dev
mailing list