Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/util/PropertyExpander/ExpandAndEncode.java
38854 views
/*1* Copyright (c) 2002, 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* @author Valerie Peng26* @bug 471621327* @bug 479785028* @summary Verify that expand(String, boolean) does not encode if29* the value is a valid URI with a scheme (it is already encoded),30* i.e. avoid double encoding.31*/32import java.io.File;33import sun.security.util.*;3435public class ExpandAndEncode {3637private static String tests[] = {38"${env.test1}/test.jar",39"file:${env.test2}/test.jar",40"file:/foo/${env.test3}",41"file:/foo/${env.test4}"42};4344private static String answers[] = {45"http://my%20home/test.jar",46"file:/my%20home/test.jar",47"file:/foo/bar%23foobar",48"file:/foo/goofy:bar%23foobar"49};5051private static boolean checkAnswer(String result, int i) {52if (result.equals(answers[i])) {53return true;54} else {55System.out.println("Test#" + i + ": expected " + answers[i]);56System.out.println("Test#" + i + ": got " + result);57return false;58}59}6061public static void main(String[] args) throws Exception {6263boolean status = true;6465System.setProperty("env.test1", "http://my%20home");66System.setProperty("env.test2", File.separator + "my home");67System.setProperty("env.test3", "bar#foobar");68System.setProperty("env.test4", "goofy:bar#foobar");6970for (int i=0; i < tests.length; i++) {71String result = PropertyExpander.expand(tests[i], true);72status &= checkAnswer(result, i);73}7475if (status) {76System.out.println("PASSED");77} else {78throw new Exception("FAILED");79}80}81}828384