8007322: untangle ftp protocol from general networking URL tests
Reviewed-by: alanb
This commit is contained in:
parent
8da1d4a40c
commit
b61bb15030
jdk/test
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -21,71 +21,235 @@
|
||||
* 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
|
||||
* 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
|
||||
* 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.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Constructor {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
URL url = null;
|
||||
String urls = "jar_urls";
|
||||
if (args.length > 0 && args[0] != null) {
|
||||
urls = args[0];
|
||||
}
|
||||
List<Entry> entries = new ArrayList<>();
|
||||
entries.addAll(Arrays.asList(fileURLs));
|
||||
entries.addAll(Arrays.asList(jarURLs));
|
||||
entries.addAll(Arrays.asList(normalHttpURLs));
|
||||
entries.addAll(Arrays.asList(abnormalHttpURLs));
|
||||
if (hasFtp())
|
||||
entries.addAll(Arrays.asList(ftpURLs));
|
||||
URL url;
|
||||
|
||||
File f = new File(urls);
|
||||
InputStream file = new FileInputStream(f);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(file));
|
||||
while(true) {
|
||||
String context = in.readLine();
|
||||
if (context == null) {
|
||||
break;
|
||||
}
|
||||
context = getValue(context);
|
||||
String spec = getValue(in.readLine());
|
||||
String expected = getValue(in.readLine());
|
||||
for (Entry e : entries) {
|
||||
if (e.context == null)
|
||||
url = new URL(e.spec);
|
||||
else
|
||||
url = new URL(new URL(e.context), e.spec);
|
||||
|
||||
if (context.equals("null")) {
|
||||
url = new URL(spec);
|
||||
} else {
|
||||
url = new URL(new URL(context), spec);
|
||||
}
|
||||
if (!(url.toString().equals(expected))) {
|
||||
throw new RuntimeException("error for: \n\tURL:" + context +
|
||||
"\n\tspec: " + spec +
|
||||
"\n\texpected: " + expected +
|
||||
if (!(url.toString().equals(e.expected))) {
|
||||
throw new RuntimeException("error for: \n\tURL:" + e.context +
|
||||
"\n\tspec: " + e.spec +
|
||||
"\n\texpected: " + e.expected +
|
||||
"\n\tactual: " + url.toString());
|
||||
} 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) {
|
||||
return value.substring(value.indexOf(':') + 2);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
public static void main(String args[]) throws Exception {
|
||||
URL.setURLStreamHandlerFactory(
|
||||
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);
|
||||
url.openConnection();
|
||||
}
|
||||
|
@ -310,7 +310,14 @@ public class Test {
|
||||
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 --
|
||||
|
||||
@ -319,8 +326,9 @@ public class Test {
|
||||
|
||||
header("RFC2396: Basic examples");
|
||||
|
||||
test("ftp://ftp.is.co.za/rfc/rfc1808.txt")
|
||||
.s("ftp").h("ftp.is.co.za").p("/rfc/rfc1808.txt").z();
|
||||
if (hasFtp())
|
||||
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")
|
||||
.s("http").h("www.math.uio.no").p("/faq/compression-faq/part1.html").z();
|
||||
@ -328,8 +336,9 @@ public class Test {
|
||||
test("http://www.w3.org/Addressing/")
|
||||
.s("http").h("www.w3.org").p("/Addressing/").z();
|
||||
|
||||
test("ftp://ds.internic.net/rfc/")
|
||||
.s("ftp").h("ds.internic.net").p("/rfc/").z();
|
||||
if (hasFtp())
|
||||
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")
|
||||
.s("http").h("www.ics.uci.edu").p("/pub/ietf/url/historical.html")
|
||||
|
@ -28,20 +28,22 @@
|
||||
*/
|
||||
|
||||
import java.net.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class URIToURLTest {
|
||||
public static void main(String args[]) throws Exception {
|
||||
String[] uris = {
|
||||
"http://jag:cafebabe@java.sun.com:94/b/c/d?q#g",
|
||||
"http://[1080:0:0:0:8:800:200C:417A]/index.html",
|
||||
"http://a/b/c/d;p?q",
|
||||
"ftp://ftp.is.co.za/rfc/rfc1808.txt",
|
||||
"mailto:mduerst@ifi.unizh.ch", // opaque url
|
||||
"http:comp.infosystems.www.servers.unix" //opaque url
|
||||
};
|
||||
List<String> uris = new ArrayList<>();
|
||||
uris.add("http://jag:cafebabe@java.sun.com:94/b/c/d?q#g");
|
||||
uris.add("http://[1080:0:0:0:8:800:200C:417A]/index.html");
|
||||
uris.add("http://a/b/c/d;p?q");
|
||||
uris.add("mailto:mduerst@ifi.unizh.ch");
|
||||
uris.add("http:comp.infosystems.www.servers.unix");
|
||||
if (hasFtp())
|
||||
uris.add("ftp://ftp.is.co.za/rfc/rfc1808.txt");
|
||||
|
||||
for (int i = 0; i < uris.length; i++) {
|
||||
URI uri = new URI(uris[i]);
|
||||
for (String uriStr : uris) {
|
||||
URI uri = new URI(uriStr);
|
||||
URL url = uri.toURL();
|
||||
String scheme = uri.getScheme();
|
||||
boolean schemeCheck = scheme == null? url.getProtocol() == null :
|
||||
@ -111,4 +113,13 @@ public class URIToURLTest {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
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
|
@ -1,27 +0,0 @@
|
||||
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
|
@ -1,75 +0,0 @@
|
||||
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
|
@ -1,83 +0,0 @@
|
||||
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
|
@ -1,67 +0,0 @@
|
||||
#
|
||||
# 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
|
@ -1,51 +0,0 @@
|
||||
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
|
@ -1,15 +0,0 @@
|
||||
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
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,90 +28,55 @@
|
||||
*/
|
||||
|
||||
import java.net.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RequestProperties {
|
||||
public static void main (String args[]) throws Exception {
|
||||
URL url0 = new URL ("http://foo.com/bar/");
|
||||
URL url1 = new URL ("file:/etc/passwd");
|
||||
URL url2 = new URL ("ftp://foo:bar@foobar.com/etc/passwd");
|
||||
URL url3 = new URL ("jar:http://foo.com/bar.html!/foo/bar");
|
||||
URLConnection urlc0 = url0.openConnection ();
|
||||
URLConnection urlc1 = url1.openConnection ();
|
||||
URLConnection urlc2 = url2.openConnection ();
|
||||
URLConnection urlc3 = url3.openConnection ();
|
||||
int count = 0;
|
||||
String s = null;
|
||||
try {
|
||||
urlc0.setRequestProperty (null, null);
|
||||
System.out.println ("http: setRequestProperty (null,) did not throw NPE");
|
||||
} catch (NullPointerException e) {
|
||||
count ++;
|
||||
}
|
||||
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 {
|
||||
urlc3.setRequestProperty (null, null);
|
||||
System.out.println ("jar: setRequestProperty (null,) did not throw NPE");
|
||||
} catch (NullPointerException e) {
|
||||
count ++;
|
||||
}
|
||||
try {
|
||||
urlc3.addRequestProperty (null, null);
|
||||
System.out.println ("jar: addRequestProperty (null,) did not throw NPE");
|
||||
} catch (NullPointerException e) {
|
||||
count ++;
|
||||
}
|
||||
if (urlc0.getRequestProperty (null) != null) {
|
||||
System.out.println ("http: getRequestProperty (null,) did not return null");
|
||||
} else {
|
||||
count ++;
|
||||
}
|
||||
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 ++;
|
||||
}
|
||||
static int failed;
|
||||
|
||||
if (count != 12) {
|
||||
throw new RuntimeException ((12 -count) + " errors") ;
|
||||
public static void main (String args[]) throws Exception {
|
||||
List<String> urls = new ArrayList<>();
|
||||
urls.add("http://foo.com/bar/");
|
||||
urls.add("jar:http://foo.com/bar.html!/foo/bar");
|
||||
urls.add("file:/etc/passwd");
|
||||
if (hasFtp())
|
||||
urls.add("ftp://foo:bar@foobar.com/etc/passwd");
|
||||
|
||||
for (String urlStr : urls)
|
||||
test(new URL(urlStr));
|
||||
|
||||
if (failed != 0)
|
||||
throw new RuntimeException(failed + " errors") ;
|
||||
}
|
||||
|
||||
static void test(URL url) throws Exception {
|
||||
URLConnection urlc = url.openConnection();
|
||||
try {
|
||||
urlc.setRequestProperty(null, null);
|
||||
System.out.println(url.getProtocol()
|
||||
+ ": setRequestProperty(null,) did not throw NPE");
|
||||
failed++;
|
||||
} catch (NullPointerException e) { /* Expected */ }
|
||||
try {
|
||||
urlc.addRequestProperty(null, null);
|
||||
System.out.println(url.getProtocol()
|
||||
+ ": addRequestProperty(null,) did not throw NPE");
|
||||
failed++;
|
||||
} catch (NullPointerException e) { /* Expected */ }
|
||||
|
||||
if (urlc.getRequestProperty(null) != null) {
|
||||
System.out.println(url.getProtocol()
|
||||
+ ": getRequestProperty(null,) did not return null");
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,11 @@
|
||||
* @summary Test URLConnection Request Proterties
|
||||
*/
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Part1:
|
||||
@ -45,28 +48,29 @@ public class RequestPropertyValues {
|
||||
}
|
||||
|
||||
public static void part1() throws Exception {
|
||||
URL[] urls = { new URL("http://localhost:8088"),
|
||||
new URL("file:/etc/passwd"),
|
||||
new URL("ftp://foo:bar@foobar.com/etc/passwd"),
|
||||
new URL("jar:http://foo.com/bar.html!/foo/bar")
|
||||
};
|
||||
List<URL> urls = new ArrayList<>();
|
||||
urls.add(new URL("http://localhost:8088"));
|
||||
urls.add(new URL("file:/etc/passwd"));
|
||||
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;
|
||||
|
||||
for (int proto = 0; proto < urls.length; proto++) {
|
||||
URLConnection uc = (URLConnection) urls[proto].openConnection();
|
||||
for (URL url : urls) {
|
||||
URLConnection uc = url.openConnection();
|
||||
try {
|
||||
uc.setRequestProperty("TestHeader", null);
|
||||
} catch (NullPointerException npe) {
|
||||
System.out.println("setRequestProperty is throwing NPE" +
|
||||
" for url: " + urls[proto]);
|
||||
" for url: " + url);
|
||||
failed = true;
|
||||
}
|
||||
try {
|
||||
uc.addRequestProperty("TestHeader", null);
|
||||
} catch (NullPointerException npe) {
|
||||
System.out.println("addRequestProperty is throwing NPE" +
|
||||
" for url: " + urls[proto]);
|
||||
" for url: " + url);
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
@ -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 {
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
ProxyTest test = new ProxyTest();
|
||||
if (hasFtp())
|
||||
new ProxyTest();
|
||||
}
|
||||
|
||||
public ProxyTest() throws Exception {
|
||||
|
Loading…
x
Reference in New Issue
Block a user