Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/util/PropertyExpander/ExpandAndEncode.java
38854 views
1
/*
2
* Copyright (c) 2002, 2003, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @author Valerie Peng
27
* @bug 4716213
28
* @bug 4797850
29
* @summary Verify that expand(String, boolean) does not encode if
30
* the value is a valid URI with a scheme (it is already encoded),
31
* i.e. avoid double encoding.
32
*/
33
import java.io.File;
34
import sun.security.util.*;
35
36
public class ExpandAndEncode {
37
38
private 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
};
44
45
private 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
};
51
52
private static boolean checkAnswer(String result, int i) {
53
if (result.equals(answers[i])) {
54
return true;
55
} else {
56
System.out.println("Test#" + i + ": expected " + answers[i]);
57
System.out.println("Test#" + i + ": got " + result);
58
return false;
59
}
60
}
61
62
public static void main(String[] args) throws Exception {
63
64
boolean status = true;
65
66
System.setProperty("env.test1", "http://my%20home");
67
System.setProperty("env.test2", File.separator + "my home");
68
System.setProperty("env.test3", "bar#foobar");
69
System.setProperty("env.test4", "goofy:bar#foobar");
70
71
for (int i=0; i < tests.length; i++) {
72
String result = PropertyExpander.expand(tests[i], true);
73
status &= checkAnswer(result, i);
74
}
75
76
if (status) {
77
System.out.println("PASSED");
78
} else {
79
throw new Exception("FAILED");
80
}
81
}
82
}
83
84