提交 14e600ae 编写于 作者: C chegar

8007322: untangle ftp protocol from general networking URL tests

Reviewed-by: alanb
上级 04e8b6e0
/* /*
* Copyright (c) 1998, 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -21,71 +21,235 @@ ...@@ -21,71 +21,235 @@
* questions. * questions.
*/ */
/* This is no longer run directly. See runconstructor.sh /*
* * @test
* * @bug 4393671
* * @summary URL constructor URL(URL context, String spec) FAILED with specific input
*/
/*
* This program tests the URL parser in the URL constructor. It * This program tests the URL parser in the URL constructor. It
* tries to construct a variety of valid URLs with a given context * tries to construct a variety of valid URLs with a given context
* (which may be null) and a variety of specs. It then compares the * (which may be null) and a variety of specs. It then compares the
* result with an expected value. * result with an expected value.
*
* It expects that a data file named "urls" be available in the
* current directory, from which it will get its testing data. The
* format of the file is:
*
* URL: null
* spec: jar:http://www.foo.com/dir1/jar.jar!/
* expected: jar:http://www.foo.com/dir1/jar.jar!/
*
* where URL is the context, spec is the spec and expected is the
* expected result. The first : must be followed by a space. Each test
* entry should be followed by a blank line.
*/ */
import java.io.*; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Constructor { public class Constructor {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
URL url = null; List<Entry> entries = new ArrayList<>();
String urls = "jar_urls"; entries.addAll(Arrays.asList(fileURLs));
if (args.length > 0 && args[0] != null) { entries.addAll(Arrays.asList(jarURLs));
urls = args[0]; entries.addAll(Arrays.asList(normalHttpURLs));
} entries.addAll(Arrays.asList(abnormalHttpURLs));
if (hasFtp())
entries.addAll(Arrays.asList(ftpURLs));
URL url;
File f = new File(urls); for (Entry e : entries) {
InputStream file = new FileInputStream(f); if (e.context == null)
BufferedReader in = new BufferedReader(new InputStreamReader(file)); url = new URL(e.spec);
while(true) { else
String context = in.readLine(); url = new URL(new URL(e.context), e.spec);
if (context == null) {
break;
}
context = getValue(context);
String spec = getValue(in.readLine());
String expected = getValue(in.readLine());
if (context.equals("null")) { if (!(url.toString().equals(e.expected))) {
url = new URL(spec); throw new RuntimeException("error for: \n\tURL:" + e.context +
} else { "\n\tspec: " + e.spec +
url = new URL(new URL(context), spec); "\n\texpected: " + e.expected +
}
if (!(url.toString().equals(expected))) {
throw new RuntimeException("error for: \n\tURL:" + context +
"\n\tspec: " + spec +
"\n\texpected: " + expected +
"\n\tactual: " + url.toString()); "\n\tactual: " + url.toString());
} else { } else {
System.out.println("success for: " + url + "\n"); //debug
//System.out.println("success for: " + url);
} }
in.readLine();
} }
in.close();
} }
private static String getValue(String value) { private static boolean hasFtp() {
return value.substring(value.indexOf(':') + 2); try {
return new java.net.URL("ftp://") != null;
} catch (java.net.MalformedURLException x) {
System.out.println("FTP not supported by this runtime.");
return false;
}
}
static class Entry {
final String context;
final String spec;
final String expected;
Entry(String context, String spec, String expected) {
this.context = context;
this.spec =spec;
this.expected = expected;
}
} }
static Entry[] fileURLs = new Entry[] {
new Entry(null,
"file://JavaSoft/Test",
"file://JavaSoft/Test"),
new Entry(null,
"file:///JavaSoft/Test",
"file:/JavaSoft/Test"),
new Entry(null,
"file:/JavaSoft/Test",
"file:/JavaSoft/Test"),
new Entry(null,
"file:/c:/JavaSoft/Test",
"file:/c:/JavaSoft/Test"),
new Entry(null,
"file:/c:/JavaSoft/Test:something",
"file:/c:/JavaSoft/Test:something"),
new Entry(null,
"file:/c:/JavaSoft/Test#anchor",
"file:/c:/JavaSoft/Test#anchor"),
new Entry("file://JavaSoft/Test",
"Test#bar",
"file://JavaSoft/Test#bar"),
new Entry("file://codrus/c:/jdk/eng/index.html",
"pulsar.html",
"file://codrus/c:/jdk/eng/pulsar.html"),
new Entry("file:///c:/jdk/eng/index.html",
"pulsar.html",
"file:/c:/jdk/eng/pulsar.html"),
new Entry("file:///jdk/eng/index.html",
"pulsar.html",
"file:/jdk/eng/pulsar.html"),
new Entry("file://JavaSoft/Test",
"file://radartoad.com/Test#bar",
"file://radartoad.com/Test#bar"),
new Entry("file://JavaSoft/Test",
"/c:/Test#bar",
"file://JavaSoft/c:/Test#bar"),
};
static Entry[] jarURLs = new Entry[] {
new Entry(null,
"jar:http://www.foo.com/dir1/jar.jar!/dir2/entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/dir2/entry.txt"),
new Entry(null,
"jar:http://www.foo.com/dir1/jar.jar!/",
"jar:http://www.foo.com/dir1/jar.jar!/"),
new Entry(null,
"jar:http://www.foo.com/dir1/jar.jar!/",
"jar:http://www.foo.com/dir1/jar.jar!/"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
"entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
"/entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
"dir1/entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
"/dir1/entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
"entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
"/entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
"/entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/dir1/",
"entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/dir2/dir3/entry2.txt",
"/dir1/entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
"/dir1/foo/entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/dir1/foo/entry.txt"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/dir1/dir2/dir3/",
"dir4/foo/entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/dir1/dir2/dir3/dir4/foo/entry.txt"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
"/dir1/foo/entry.txt",
"jar:http://www.foo.com/dir1/jar.jar!/dir1/foo/entry.txt"),
new Entry(null,
"jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor",
"jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/foo.txt",
"#anchor",
"jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor"),
new Entry("jar:http://www.foo.com/dir1/jar.jar!/foo/bar/",
"baz/quux#anchor",
"jar:http://www.foo.com/dir1/jar.jar!/foo/bar/baz/quux#anchor"),
new Entry("jar:http://balloo.com/olle.jar!/",
"p2",
"jar:http://balloo.com/olle.jar!/p2")
};
static Entry[] normalHttpURLs = new Entry[] {
new Entry("http://a/b/c/d;p?q", "g", "http://a/b/c/g"),
new Entry("http://a/b/c/d;p?q", "./g", "http://a/b/c/g"),
new Entry("http://a/b/c/d;p?q", "g/", "http://a/b/c/g/"),
new Entry("http://a/b/c/d;p?q", "/g", "http://a/g"),
new Entry("http://a/b/c/d;p?q", "//g", "http://g"),
new Entry("http://a/b/c/d;p?q", "?y", "http://a/b/c/?y"),
new Entry("http://a/b/c/d;p?q", "g?y", "http://a/b/c/g?y"),
new Entry("http://a/b/c/d;p?q", "g#s", "http://a/b/c/g#s"),
new Entry("http://a/b/c/d;p?q", "g?y#s", "http://a/b/c/g?y#s"),
new Entry("http://a/b/c/d;p?q", ";x", "http://a/b/c/;x"),
new Entry("http://a/b/c/d;p?q", "g;x", "http://a/b/c/g;x"),
new Entry("http://a/b/c/d;p?q", "g;x?y#s", "http://a/b/c/g;x?y#s"),
new Entry("http://a/b/c/d;p?q", ".", "http://a/b/c/"),
new Entry("http://a/b/c/d;p?q", "./", "http://a/b/c/"),
new Entry("http://a/b/c/d;p?q", "..", "http://a/b/"),
new Entry("http://a/b/c/d;p?q", "../", "http://a/b/"),
new Entry("http://a/b/c/d;p?q", "../g", "http://a/b/g"),
new Entry("http://a/b/c/d;p?q", "../..", "http://a/"),
new Entry("http://a/b/c/d;p?q", "../../", "http://a/"),
new Entry("http://a/b/c/d;p?q", "../../g", "http://a/g"),
new Entry(null,
"http://www.javasoft.com/jdc/community/chat/index.html#javalive?frontpage-jdc",
"http://www.javasoft.com/jdc/community/chat/index.html#javalive?frontpage-jdc")
};
static Entry[] abnormalHttpURLs = new Entry[] {
new Entry("http://a/b/c/d;p?q", "../../../g", "http://a/../g"),
new Entry("http://a/b/c/d;p?q", "../../../../g", "http://a/../../g"),
new Entry("http://a/b/c/d;p?q", "/./g", "http://a/./g"),
new Entry("http://a/b/c/d;p?q", "/../g", "http://a/../g"),
new Entry("http://a/b/c/d;p?q", ".g", "http://a/b/c/.g"),
new Entry("http://a/b/c/d;p?q", "g.", "http://a/b/c/g."),
new Entry("http://a/b/c/d;p?q", "./../g", "http://a/b/g"),
new Entry("http://a/b/c/d;p?q", "./g/.", "http://a/b/c/g/"),
new Entry("http://a/b/c/d;p?q", "g/./h", "http://a/b/c/g/h"),
new Entry("http://a/b/c/d;p?q", "g;x=1/./y", "http://a/b/c/g;x=1/y"),
new Entry("http://a/b/c/d;p?q", "g;x=1/../y", "http://a/b/c/y")
};
static Entry[] ftpURLs = new Entry[] {
new Entry(null,
"ftp://ftp.foo.com/dir1/entry.txt",
"ftp://ftp.foo.com/dir1/entry.txt"),
new Entry(null,
"ftp://br:pwd@ftp.foo.com/dir1/jar.jar",
"ftp://br:pwd@ftp.foo.com/dir1/jar.jar"),
new Entry("ftp://ftp.foo.com/dir1/foo.txt",
"bar.txt",
"ftp://ftp.foo.com/dir1/bar.txt"),
new Entry("ftp://ftp.foo.com/dir1/jar.jar",
"/entry.txt",
"ftp://ftp.foo.com/entry.txt"),
new Entry("ftp://ftp.foo.com/dir1/jar.jar",
"dir1/entry.txt",
"ftp://ftp.foo.com/dir1/dir1/entry.txt"),
new Entry("ftp://ftp.foo.com/dir1/jar.jar",
"/dir1/entry.txt",
"ftp://ftp.foo.com/dir1/entry.txt"),
new Entry("ftp://br:pwd@ftp.foo.com/dir1/jar.jar",
"/dir1/entry.txt",
"ftp://br:pwd@ftp.foo.com/dir1/entry.txt")
};
} }
...@@ -36,7 +36,7 @@ public class HandlerLoop { ...@@ -36,7 +36,7 @@ public class HandlerLoop {
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
URL.setURLStreamHandlerFactory( URL.setURLStreamHandlerFactory(
new HandlerFactory("sun.net.www.protocol")); new HandlerFactory("sun.net.www.protocol"));
URL url = new URL("file://bogus/index.html"); URL url = new URL("file:///bogus/index.html");
System.out.println("url = " + url); System.out.println("url = " + url);
url.openConnection(); url.openConnection();
} }
......
...@@ -310,7 +310,14 @@ public class Test { ...@@ -310,7 +310,14 @@ public class Test {
throw new RuntimeException("Test failed"); throw new RuntimeException("Test failed");
} }
private static boolean hasFtp() {
try {
return new java.net.URL("ftp://") != null;
} catch (java.net.MalformedURLException x) {
System.out.println("FTP not supported by this runtime.");
return false;
}
}
// -- Tests -- // -- Tests --
...@@ -319,8 +326,9 @@ public class Test { ...@@ -319,8 +326,9 @@ public class Test {
header("RFC2396: Basic examples"); header("RFC2396: Basic examples");
test("ftp://ftp.is.co.za/rfc/rfc1808.txt") if (hasFtp())
.s("ftp").h("ftp.is.co.za").p("/rfc/rfc1808.txt").z(); test("ftp://ftp.is.co.za/rfc/rfc1808.txt")
.s("ftp").h("ftp.is.co.za").p("/rfc/rfc1808.txt").z();
test("http://www.math.uio.no/faq/compression-faq/part1.html") test("http://www.math.uio.no/faq/compression-faq/part1.html")
.s("http").h("www.math.uio.no").p("/faq/compression-faq/part1.html").z(); .s("http").h("www.math.uio.no").p("/faq/compression-faq/part1.html").z();
...@@ -328,8 +336,9 @@ public class Test { ...@@ -328,8 +336,9 @@ public class Test {
test("http://www.w3.org/Addressing/") test("http://www.w3.org/Addressing/")
.s("http").h("www.w3.org").p("/Addressing/").z(); .s("http").h("www.w3.org").p("/Addressing/").z();
test("ftp://ds.internic.net/rfc/") if (hasFtp())
.s("ftp").h("ds.internic.net").p("/rfc/").z(); test("ftp://ds.internic.net/rfc/")
.s("ftp").h("ds.internic.net").p("/rfc/").z();
test("http://www.ics.uci.edu/pub/ietf/url/historical.html#WARNING") test("http://www.ics.uci.edu/pub/ietf/url/historical.html#WARNING")
.s("http").h("www.ics.uci.edu").p("/pub/ietf/url/historical.html") .s("http").h("www.ics.uci.edu").p("/pub/ietf/url/historical.html")
......
...@@ -28,20 +28,22 @@ ...@@ -28,20 +28,22 @@
*/ */
import java.net.*; import java.net.*;
import java.util.ArrayList;
import java.util.List;
public class URIToURLTest { public class URIToURLTest {
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
String[] uris = { List<String> uris = new ArrayList<>();
"http://jag:cafebabe@java.sun.com:94/b/c/d?q#g", uris.add("http://jag:cafebabe@java.sun.com:94/b/c/d?q#g");
"http://[1080:0:0:0:8:800:200C:417A]/index.html", uris.add("http://[1080:0:0:0:8:800:200C:417A]/index.html");
"http://a/b/c/d;p?q", uris.add("http://a/b/c/d;p?q");
"ftp://ftp.is.co.za/rfc/rfc1808.txt", uris.add("mailto:mduerst@ifi.unizh.ch");
"mailto:mduerst@ifi.unizh.ch", // opaque url uris.add("http:comp.infosystems.www.servers.unix");
"http:comp.infosystems.www.servers.unix" //opaque url if (hasFtp())
}; uris.add("ftp://ftp.is.co.za/rfc/rfc1808.txt");
for (int i = 0; i < uris.length; i++) { for (String uriStr : uris) {
URI uri = new URI(uris[i]); URI uri = new URI(uriStr);
URL url = uri.toURL(); URL url = uri.toURL();
String scheme = uri.getScheme(); String scheme = uri.getScheme();
boolean schemeCheck = scheme == null? url.getProtocol() == null : boolean schemeCheck = scheme == null? url.getProtocol() == null :
...@@ -111,4 +113,13 @@ public class URIToURLTest { ...@@ -111,4 +113,13 @@ public class URIToURLTest {
url.getRef()); url.getRef());
} }
} }
private static boolean hasFtp() {
try {
return new java.net.URL("ftp://") != null;
} catch (java.net.MalformedURLException x) {
System.out.println("FTP not supported by this runtime.");
return false;
}
}
} }
URL: http://a/b/c/d;p?q
spec: ../../../g
expected: http://a/../g
URL: http://a/b/c/d;p?q
spec: ../../../../g
expected: http://a/../../g
URL: http://a/b/c/d;p?q
spec: /./g
expected: http://a/./g
URL: http://a/b/c/d;p?q
spec: /../g
expected: http://a/../g
URL: http://a/b/c/d;p?q
spec: .g
expected: http://a/b/c/.g
URL: http://a/b/c/d;p?q
spec: g.
expected: http://a/b/c/g.
URL: http://a/b/c/d;p?q
spec: ./../g
expected: http://a/b/g
URL: http://a/b/c/d;p?q
spec: ./g/.
expected: http://a/b/c/g/
URL: http://a/b/c/d;p?q
spec: g/./h
expected: http://a/b/c/g/h
URL: http://a/b/c/d;p?q
spec: g;x=1/./y
expected: http://a/b/c/g;x=1/y
URL: http://a/b/c/d;p?q
spec: g;x=1/../y
expected: http://a/b/c/y
URL: null
spec: ftp://ftp.foo.com/dir1/entry.txt
expected: ftp://ftp.foo.com/dir1/entry.txt
URL: null
spec: ftp://br:pwd@ftp.foo.com/dir1/jar.jar
expected: ftp://br:pwd@ftp.foo.com/dir1/jar.jar
URL: ftp://ftp.foo.com/dir1/foo.txt
spec: bar.txt
expected: ftp://ftp.foo.com/dir1/bar.txt
URL: ftp://ftp.foo.com/dir1/jar.jar
spec: /entry.txt
expected: ftp://ftp.foo.com/entry.txt
URL: ftp://ftp.foo.com/dir1/jar.jar
spec: dir1/entry.txt
expected: ftp://ftp.foo.com/dir1/dir1/entry.txt
URL: ftp://ftp.foo.com/dir1/jar.jar
spec: /dir1/entry.txt
expected: ftp://ftp.foo.com/dir1/entry.txt
URL: ftp://br:pwd@ftp.foo.com/dir1/jar.jar
spec: /dir1/entry.txt
expected: ftp://br:pwd@ftp.foo.com/dir1/entry.txt
URL: null
spec: jar:http://www.foo.com/dir1/jar.jar!/dir2/entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/dir2/entry.txt
URL: null
spec: jar:http://www.foo.com/dir1/jar.jar!/
expected: jar:http://www.foo.com/dir1/jar.jar!/
URL: null
spec: jar:http://www.foo.com/dir1/jar.jar!/
expected: jar:http://www.foo.com/dir1/jar.jar!/
URL: jar:http://www.foo.com/dir1/jar.jar!/
spec: entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/entry.txt
URL: jar:http://www.foo.com/dir1/jar.jar!/
spec: /entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/entry.txt
URL: jar:http://www.foo.com/dir1/jar.jar!/
spec: dir1/entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt
URL: jar:http://www.foo.com/dir1/jar.jar!/
spec: /dir1/entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt
URL: jar:http://www.foo.com/dir1/jar.jar!/
spec: entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/entry.txt
URL: jar:http://www.foo.com/dir1/jar.jar!/
spec: /entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/entry.txt
URL: jar:http://www.foo.com/dir1/jar.jar!/
spec: /entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/entry.txt
URL: jar:http://www.foo.com/dir1/jar.jar!/dir1/
spec: entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt
URL: jar:http://www.foo.com/dir1/jar.jar!/dir2/dir3/entry2.txt
spec: /dir1/entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt
URL: jar:http://www.foo.com/dir1/jar.jar!/
spec: /dir1/foo/entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/foo/entry.txt
URL: jar:http://www.foo.com/dir1/jar.jar!/dir1/dir2/dir3/
spec: dir4/foo/entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/dir2/dir3/dir4/foo/entry.txt
URL: jar:http://www.foo.com/dir1/jar.jar!/
spec: /dir1/foo/entry.txt
expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/foo/entry.txt
URL: null
spec: jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor
expected: jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor
URL: jar:http://www.foo.com/dir1/jar.jar!/foo.txt
spec: #anchor
expected: jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor
URL: jar:http://www.foo.com/dir1/jar.jar!/foo/bar/
spec: baz/quux#anchor
expected: jar:http://www.foo.com/dir1/jar.jar!/foo/bar/baz/quux#anchor
URL: jar:http://balloo.com/olle.jar!/
spec: p2
expected: jar:http://balloo.com/olle.jar!/p2
URL: http://a/b/c/d;p?q
spec: g
expected: http://a/b/c/g
URL: http://a/b/c/d;p?q
spec: ./g
expected: http://a/b/c/g
URL: http://a/b/c/d;p?q
spec: g/
expected: http://a/b/c/g/
URL: http://a/b/c/d;p?q
spec: /g
expected: http://a/g
URL: http://a/b/c/d;p?q
spec: //g
expected: http://g
URL: http://a/b/c/d;p?q
spec: ?y
expected: http://a/b/c/?y
URL: http://a/b/c/d;p?q
spec: g?y
expected: http://a/b/c/g?y
URL: http://a/b/c/d;p?q
spec: g#s
expected: http://a/b/c/g#s
URL: http://a/b/c/d;p?q
spec: g?y#s
expected: http://a/b/c/g?y#s
URL: http://a/b/c/d;p?q
spec: ;x
expected: http://a/b/c/;x
URL: http://a/b/c/d;p?q
spec: g;x
expected: http://a/b/c/g;x
URL: http://a/b/c/d;p?q
spec: g;x?y#s
expected: http://a/b/c/g;x?y#s
URL: http://a/b/c/d;p?q
spec: .
expected: http://a/b/c/
URL: http://a/b/c/d;p?q
spec: ./
expected: http://a/b/c/
URL: http://a/b/c/d;p?q
spec: ..
expected: http://a/b/
URL: http://a/b/c/d;p?q
spec: ../
expected: http://a/b/
URL: http://a/b/c/d;p?q
spec: ../g
expected: http://a/b/g
URL: http://a/b/c/d;p?q
spec: ../..
expected: http://a/
URL: http://a/b/c/d;p?q
spec: ../../
expected: http://a/
URL: http://a/b/c/d;p?q
spec: ../../g
expected: http://a/g
URL: null
spec: http://www.javasoft.com/jdc/community/chat/index.html#javalive?frontpage-jdc
expected: http://www.javasoft.com/jdc/community/chat/index.html#javalive?frontpage-jdc
#
# Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# @test
# @bug 4393671
# @summary URL constructor URL(URL context, String spec) FAILED with specific input in merlin
#
OS=`uname -s`
case "$OS" in
SunOS | Linux | Darwin )
PS=":"
FS="/"
;;
CYGWIN* )
PS=";"
FS="/"
;;
Windows* )
PS=";"
FS="\\"
;;
* )
echo "Unrecognized system!"
exit 1;
;;
esac
${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . \
${TESTSRC}${FS}Constructor.java
failures=0
go() {
echo ''
${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} Constructor $1
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
}
go ${TESTSRC}${FS}share_file_urls
go ${TESTSRC}${FS}jar_urls
go ${TESTSRC}${FS}normal_http_urls
go ${TESTSRC}${FS}ftp_urls
go ${TESTSRC}${FS}abnormal_http_urls
if [ "$failures" != "0" ]; then
echo $failures tests failed
exit 1;
fi
URL: null
spec: file://JavaSoft/Test
expected: file://JavaSoft/Test
URL: null
spec: file:///JavaSoft/Test
expected: file:/JavaSoft/Test
URL: null
spec: file:/JavaSoft/Test
expected: file:/JavaSoft/Test
URL: null
spec: file:/c:/JavaSoft/Test
expected: file:/c:/JavaSoft/Test
URL: null
spec: file:/c:/JavaSoft/Test:something
expected: file:/c:/JavaSoft/Test:something
URL: null
spec: file:/c:/JavaSoft/Test#anchor
expected: file:/c:/JavaSoft/Test#anchor
URL: null
spec: file:/JavaSoft/Test
expected: file:/JavaSoft/Test
URL: file://JavaSoft/Test
spec: Test#bar
expected: file://JavaSoft/Test#bar
URL: file://codrus/c:/jdk/eng/index.html
spec: pulsar.html
expected: file://codrus/c:/jdk/eng/pulsar.html
URL: file:///c:/jdk/eng/index.html
spec: pulsar.html
expected: file:/c:/jdk/eng/pulsar.html
URL: file:///jdk/eng/index.html
spec: pulsar.html
expected: file:/jdk/eng/pulsar.html
URL: file://JavaSoft/Test
spec: file://radartoad.com/Test#bar
expected: file://radartoad.com/Test#bar
URL: file://JavaSoft/Test
spec: /c:/Test#bar
expected: file://JavaSoft/c:/Test#bar
\ No newline at end of file
URL: null
spec: file://c:\JavaSoft\Test
expected: file://c:/JavaSoft/Test
URL: null
spec: file:/c:\JavaSoft\Test
expected: file:/c:/JavaSoft/Test
URL: null
spec: file:/c:\JavaSoft\Test:something#anchor
expected: file:/c:/JavaSoft/Test:something#anchor
URL: file:///c:\jdk\eng\index.html
spec: pulsar.html
expected: file:/c:/jdk/eng/pulsar.html
\ No newline at end of file
/* /*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2013 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,90 +28,55 @@ ...@@ -28,90 +28,55 @@
*/ */
import java.net.*; import java.net.*;
import java.util.ArrayList;
import java.util.List;
public class RequestProperties { public class RequestProperties {
static int failed;
public static void main (String args[]) throws Exception { public static void main (String args[]) throws Exception {
URL url0 = new URL ("http://foo.com/bar/"); List<String> urls = new ArrayList<>();
URL url1 = new URL ("file:/etc/passwd"); urls.add("http://foo.com/bar/");
URL url2 = new URL ("ftp://foo:bar@foobar.com/etc/passwd"); urls.add("jar:http://foo.com/bar.html!/foo/bar");
URL url3 = new URL ("jar:http://foo.com/bar.html!/foo/bar"); urls.add("file:/etc/passwd");
URLConnection urlc0 = url0.openConnection (); if (hasFtp())
URLConnection urlc1 = url1.openConnection (); urls.add("ftp://foo:bar@foobar.com/etc/passwd");
URLConnection urlc2 = url2.openConnection ();
URLConnection urlc3 = url3.openConnection (); for (String urlStr : urls)
int count = 0; test(new URL(urlStr));
String s = null;
try { if (failed != 0)
urlc0.setRequestProperty (null, null); throw new RuntimeException(failed + " errors") ;
System.out.println ("http: setRequestProperty (null,) did not throw NPE"); }
} catch (NullPointerException e) {
count ++; static void test(URL url) throws Exception {
} URLConnection urlc = url.openConnection();
try {
urlc0.addRequestProperty (null, null);
System.out.println ("http: addRequestProperty (null,) did not throw NPE");
} catch (NullPointerException e) {
count ++;
}
try {
urlc1.setRequestProperty (null, null);
System.out.println ("file: setRequestProperty (null,) did not throw NPE");
} catch (NullPointerException e) {
count ++;
}
try {
urlc1.addRequestProperty (null, null);
System.out.println ("file: addRequestProperty (null,) did not throw NPE");
} catch (NullPointerException e) {
count ++;
}
try {
urlc2.setRequestProperty (null, null);
System.out.println ("ftp: setRequestProperty (null,) did not throw NPE");
} catch (NullPointerException e) {
count ++;
}
try {
urlc2.addRequestProperty (null, null);
System.out.println ("ftp: addRequestProperty (null,) did not throw NPE");
} catch (NullPointerException e) {
count ++;
}
try { try {
urlc3.setRequestProperty (null, null); urlc.setRequestProperty(null, null);
System.out.println ("jar: setRequestProperty (null,) did not throw NPE"); System.out.println(url.getProtocol()
} catch (NullPointerException e) { + ": setRequestProperty(null,) did not throw NPE");
count ++; failed++;
} } catch (NullPointerException e) { /* Expected */ }
try { try {
urlc3.addRequestProperty (null, null); urlc.addRequestProperty(null, null);
System.out.println ("jar: addRequestProperty (null,) did not throw NPE"); System.out.println(url.getProtocol()
} catch (NullPointerException e) { + ": addRequestProperty(null,) did not throw NPE");
count ++; failed++;
} } catch (NullPointerException e) { /* Expected */ }
if (urlc0.getRequestProperty (null) != null) {
System.out.println ("http: getRequestProperty (null,) did not return null"); if (urlc.getRequestProperty(null) != null) {
} else { System.out.println(url.getProtocol()
count ++; + ": getRequestProperty(null,) did not return null");
} failed++;
if (urlc1.getRequestProperty (null) != null) {
System.out.println ("file: getRequestProperty (null,) did not return null");
} else {
count ++;
}
if (urlc2.getRequestProperty (null) != null) {
System.out.println ("ftp: getRequestProperty (null,) did not return null");
} else {
count ++;
}
if (urlc2.getRequestProperty (null) != null) {
System.out.println ("jar: getRequestProperty (null,) did not return null");
} else {
count ++;
} }
}
if (count != 12) { private static boolean hasFtp() {
throw new RuntimeException ((12 -count) + " errors") ; try {
return new java.net.URL("ftp://") != null;
} catch (java.net.MalformedURLException x) {
System.out.println("FTP not supported by this runtime.");
return false;
} }
} }
} }
...@@ -27,8 +27,11 @@ ...@@ -27,8 +27,11 @@
* @summary Test URLConnection Request Proterties * @summary Test URLConnection Request Proterties
*/ */
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
/** /**
* Part1: * Part1:
...@@ -45,28 +48,29 @@ public class RequestPropertyValues { ...@@ -45,28 +48,29 @@ public class RequestPropertyValues {
} }
public static void part1() throws Exception { public static void part1() throws Exception {
URL[] urls = { new URL("http://localhost:8088"), List<URL> urls = new ArrayList<>();
new URL("file:/etc/passwd"), urls.add(new URL("http://localhost:8088"));
new URL("ftp://foo:bar@foobar.com/etc/passwd"), urls.add(new URL("file:/etc/passwd"));
new URL("jar:http://foo.com/bar.html!/foo/bar") urls.add(new URL("jar:http://foo.com/bar.html!/foo/bar"));
}; if (hasFtp())
urls.add(new URL("ftp://foo:bar@foobar.com/etc/passwd"));
boolean failed = false; boolean failed = false;
for (int proto = 0; proto < urls.length; proto++) { for (URL url : urls) {
URLConnection uc = (URLConnection) urls[proto].openConnection(); URLConnection uc = url.openConnection();
try { try {
uc.setRequestProperty("TestHeader", null); uc.setRequestProperty("TestHeader", null);
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
System.out.println("setRequestProperty is throwing NPE" + System.out.println("setRequestProperty is throwing NPE" +
" for url: " + urls[proto]); " for url: " + url);
failed = true; failed = true;
} }
try { try {
uc.addRequestProperty("TestHeader", null); uc.addRequestProperty("TestHeader", null);
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
System.out.println("addRequestProperty is throwing NPE" + System.out.println("addRequestProperty is throwing NPE" +
" for url: " + urls[proto]); " for url: " + url);
failed = true; failed = true;
} }
} }
...@@ -110,4 +114,12 @@ public class RequestPropertyValues { ...@@ -110,4 +114,12 @@ public class RequestPropertyValues {
} }
} }
private static boolean hasFtp() {
try {
return new java.net.URL("ftp://") != null;
} catch (java.net.MalformedURLException x) {
System.out.println("FTP not supported by this runtime.");
return false;
}
}
} }
...@@ -161,8 +161,18 @@ public class ProxyTest { ...@@ -161,8 +161,18 @@ public class ProxyTest {
} }
} }
private static boolean hasFtp() {
try {
return new java.net.URL("ftp://") != null;
} catch (java.net.MalformedURLException x) {
System.out.println("FTP not supported by this runtime.");
return false;
}
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
ProxyTest test = new ProxyTest(); if (hasFtp())
new ProxyTest();
} }
public ProxyTest() throws Exception { public ProxyTest() throws Exception {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册