Path: blob/master/test/jdk/java/net/URL/B4148751.java
41149 views
/*1* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 414875126* @summary URL.sameFile return false on URL's, that are equal modulo url-encoding27*/2829import java.net.*;3031public class B414875132{3334// unencoded parameters3536final static String scheme = "http";37final static String auth = "web2.javasoft.com";38final static String path = "/some file.html";39final static String unencoded = "http://web2.javasoft.com/some file.html";4041// encoded URL / URI42final static String encoded = "http://web2.javasoft.com/some%20file.html";4344public static void main(String args[]) throws URISyntaxException,45MalformedURLException {4647URL url = null;48URL url1 = null;4950try {51url = new URL(unencoded);52url1 = new URL(encoded);53}54catch(Exception e) {55System.out.println("Unexpected exception :" + e);56System.exit(-1);57}5859if(url.sameFile(url1)) {60throw new RuntimeException ("URL does not understand escaping");61}6263/* check decoding of a URL */6465URI uri = url1.toURI();66if (!uri.getPath().equals (path)) {67throw new RuntimeException ("Got: " + uri.getPath() + " expected: " +68path);69}7071/* check encoding of a URL */7273URI uri1 = new URI (scheme, auth, path);74url = uri.toURL();75if (!url.toString().equals (encoded)) {76throw new RuntimeException ("Got: " + url.toString() + " expected: " +77encoded);78}79}80}818283