Path: blob/master/test/jdk/sun/net/www/protocol/jar/CanonicalizationTest.java
41159 views
/*1* Copyright (c) 2018, 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 819784926* @summary Sanity test the special canonicalization logic for jar resources27*/2829import java.net.URL;3031public class CanonicalizationTest {32public static void main(String args[]) throws Exception {33URL base = new URL("jar:file:/foo!/");3435check(new URL(base, ""), "jar:file:/foo!/");36check(new URL(base, "."), "jar:file:/foo!/");37check(new URL(base, ".."), "jar:file:/foo!");38check(new URL(base, ".x"), "jar:file:/foo!/.x");39check(new URL(base, "..x"), "jar:file:/foo!/..x");40check(new URL(base, "..."), "jar:file:/foo!/...");41check(new URL(base, "foo/."), "jar:file:/foo!/foo/");42check(new URL(base, "foo/.."), "jar:file:/foo!/");43check(new URL(base, "foo/.x"), "jar:file:/foo!/foo/.x");44check(new URL(base, "foo/..x"), "jar:file:/foo!/foo/..x");45check(new URL(base, "foo/..."), "jar:file:/foo!/foo/...");46check(new URL(base, "foo/./"), "jar:file:/foo!/foo/");47check(new URL(base, "foo/../"), "jar:file:/foo!/");48check(new URL(base, "foo/.../"), "jar:file:/foo!/foo/.../");49check(new URL(base, "foo/../../"), "jar:file:/foo!/");50check(new URL(base, "foo/../,,/.."), "jar:file:/foo!/");51check(new URL(base, "foo/../."), "jar:file:/foo!/");52check(new URL(base, "foo/../.x"), "jar:file:/foo!/.x");53}5455private static void check(URL url, String expected) {56if (!url.toString().equals(expected)) {57throw new AssertionError("Expected " + url + " to equal " + expected);58}59}60}616263