J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /** |
| 25 | * @test |
| 26 | * @bug 4148751 |
| 27 | * @summary URL.sameFile return false on URL's, that are equal modulo url-encoding |
| 28 | */ |
| 29 | |
| 30 | import java.net.*; |
| 31 | |
| 32 | public class B4148751 |
| 33 | { |
| 34 | |
| 35 | // unencoded parameters |
| 36 | |
| 37 | final static String scheme = "http"; |
| 38 | final static String auth = "web2.javasoft.com"; |
| 39 | final static String path = "/some file.html"; |
| 40 | final static String unencoded = "http://web2.javasoft.com/some file.html"; |
| 41 | |
| 42 | // encoded URL / URI |
| 43 | final static String encoded = "http://web2.javasoft.com/some%20file.html"; |
| 44 | |
| 45 | public static void main(String args[]) throws URISyntaxException, |
| 46 | MalformedURLException { |
| 47 | |
| 48 | URL url = null; |
| 49 | URL url1 = null; |
| 50 | |
| 51 | try { |
| 52 | url = new URL(unencoded); |
| 53 | url1 = new URL(encoded); |
| 54 | } |
| 55 | catch(Exception e) { |
| 56 | System.out.println("Unexpected exception :" + e); |
| 57 | System.exit(-1); |
| 58 | } |
| 59 | |
| 60 | if(url.sameFile(url1)) { |
| 61 | throw new RuntimeException ("URL does not understand escaping"); |
| 62 | } |
| 63 | |
| 64 | /* check decoding of a URL */ |
| 65 | |
| 66 | URI uri = url1.toURI(); |
| 67 | if (!uri.getPath().equals (path)) { |
| 68 | throw new RuntimeException ("Got: " + uri.getPath() + " expected: " + |
| 69 | path); |
| 70 | } |
| 71 | |
| 72 | /* check encoding of a URL */ |
| 73 | |
| 74 | URI uri1 = new URI (scheme, auth, path); |
| 75 | url = uri.toURL(); |
| 76 | if (!url.toString().equals (encoded)) { |
| 77 | throw new RuntimeException ("Got: " + url.toString() + " expected: " + |
| 78 | encoded); |
| 79 | } |
| 80 | } |
| 81 | } |