B4148751.java revision 0
63N/A/*
63N/A * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
63N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
63N/A *
63N/A * This code is free software; you can redistribute it and/or modify it
63N/A * under the terms of the GNU General Public License version 2 only, as
63N/A * published by the Free Software Foundation.
63N/A *
63N/A * This code is distributed in the hope that it will be useful, but WITHOUT
63N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
63N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
63N/A * version 2 for more details (a copy is included in the LICENSE file that
63N/A * accompanied this code).
63N/A *
63N/A * You should have received a copy of the GNU General Public License version
63N/A * 2 along with this work; if not, write to the Free Software Foundation,
63N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
63N/A *
63N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
63N/A * CA 95054 USA or visit www.sun.com if you need additional information or
63N/A * have any questions.
63N/A */
63N/A
63N/A/**
63N/A * @test
63N/A * @bug 4148751
63N/A * @summary URL.sameFile return false on URL's, that are equal modulo url-encoding
63N/A */
63N/A
63N/Aimport java.net.*;
63N/A
63N/Apublic class B4148751
63N/A{
63N/A
63N/A // unencoded parameters
63N/A
63N/A final static String scheme = "http";
63N/A final static String auth = "web2.javasoft.com";
63N/A final static String path = "/some file.html";
63N/A final static String unencoded = "http://web2.javasoft.com/some file.html";
63N/A
63N/A // encoded URL / URI
63N/A final static String encoded = "http://web2.javasoft.com/some%20file.html";
63N/A
63N/A public static void main(String args[]) throws URISyntaxException,
63N/A MalformedURLException {
63N/A
63N/A URL url = null;
63N/A URL url1 = null;
63N/A
63N/A try {
63N/A url = new URL(unencoded);
63N/A url1 = new URL(encoded);
63N/A }
63N/A catch(Exception e) {
63N/A System.out.println("Unexpected exception :" + e);
63N/A System.exit(-1);
63N/A }
63N/A
63N/A if(url.sameFile(url1)) {
63N/A throw new RuntimeException ("URL does not understand escaping");
63N/A }
63N/A
63N/A /* check decoding of a URL */
63N/A
63N/A URI uri = url1.toURI();
63N/A if (!uri.getPath().equals (path)) {
63N/A throw new RuntimeException ("Got: " + uri.getPath() + " expected: " +
63N/A path);
63N/A }
63N/A
63N/A /* check encoding of a URL */
63N/A
63N/A URI uri1 = new URI (scheme, auth, path);
url = uri.toURL();
if (!url.toString().equals (encoded)) {
throw new RuntimeException ("Got: " + url.toString() + " expected: " +
encoded);
}
}
}