Path: blob/master/test/jdk/sun/security/util/PropertyExpander/ExpandAndEncode.java
41152 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* @modules java.base/sun.security.util29* @summary Verify that expand(String, boolean) does not encode if30* the value is a valid URI with a scheme (it is already encoded),31* i.e. avoid double encoding.32*/33import java.io.File;34import sun.security.util.*;3536public class ExpandAndEncode {3738private static String tests[] = {39"${env.test1}/test.jar",40"file:${env.test2}/test.jar",41"file:/foo/${env.test3}",42"file:/foo/${env.test4}"43};4445private static String answers[] = {46"http://my%20home/test.jar",47"file:/my%20home/test.jar",48"file:/foo/bar%23foobar",49"file:/foo/goofy:bar%23foobar"50};5152private static boolean checkAnswer(String result, int i) {53if (result.equals(answers[i])) {54return true;55} else {56System.out.println("Test#" + i + ": expected " + answers[i]);57System.out.println("Test#" + i + ": got " + result);58return false;59}60}6162public static void main(String[] args) throws Exception {6364boolean status = true;6566System.setProperty("env.test1", "http://my%20home");67System.setProperty("env.test2", File.separator + "my home");68System.setProperty("env.test3", "bar#foobar");69System.setProperty("env.test4", "goofy:bar#foobar");7071for (int i=0; i < tests.length; i++) {72String result = PropertyExpander.expand(tests[i], true);73status &= checkAnswer(result, i);74}7576if (status) {77System.out.println("PASSED");78} else {79throw new Exception("FAILED");80}81}82}838485