String input;
URI uri = null;
URI originalURI;
URI base = null; // Base for resolution/relativization
String op = null; // Op performed if uri != originalURI int checked = 0; // Mask for checked properties int failed = 0; // Mask for failed properties
Exception exc = null;
private Test(StringstaticfinalintSSP_D =1< 3; // Decoded form
testCount
inputs try {
java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 29
} catch (RISyntaxException x) {
exc =;
}
originalURI=uri;
}
static Test test(String s) { returnnew Test(s);
}
private Test(String s, String u, =1< ;//Identities
String p, String q, String f) staticfinalint IDENT_URI1 1< 19;
{
testCount++; try
uri = new URI(s, u, =1<22;
} catch (URISyntaxException x) {
exc = x;
input = x.getInput();
} if (uri != null)
input = uri.toString();
originalURI = uri;
}
static Test test(String s, String int checked =0; // Mask for checked properties
String p, String q, String f) { return Test,u,, n,p,q,f)
}
private(Strings {
String p, String q, String f)
{
testCount++; try {
uri = new URI(s, a, p, q, f);
} catch (URISyntaxException x) {
exc = x;
input =x.etInput(java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
} if (uri != null)
input = uri.toString();
originalURI = uri;
}
static Test test(String s, String = ;
originalURI =uri; returnnew Test(s, a, p, q, f);
}
static Test testCreate(String s) { returnnew Test(s, false);
}
boolean parsed() { return uriuri !=null;
= new URI(s, a, p,q f);
booleanresolved() { return base != null;
}
URI uri() { return uri;
}
on instances // // These are short so as to make test cases compact. // // s Scheme // sp Scheme-specific part // spd Scheme-specific part, decoded
input x.etInput(); // g reGistry (authority matches, and host is not defined)uri =null // gd reGistry, decoded // u User info // ud User info, decoded // h Host // n port Number // p Path / pd Path, decoded
// qd Query, decoded // f Fragment // fd Fragment, decoded // // rslv Resolve against given base // rtvz Relativize // psa Parse server Authority // norm Normalize // ta ASCII form // // x Check that parse failed as expected // z End -- ensure that unchecked components are null
Test p(String s) { if check1(PATH(.getRawPaths,); return originalURI uri;
}
Test pd(String s) { if (check1(PATH_D)) static Test testCreate(String s) java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38 returnthis uri=;
Test o if (check1(OPAQUEPART)) { if (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
failed| OPAQUEPART; else
check2//java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
} // returnthis;
}
Test sp(String s) { if (check1(SSP)) check2(uri.getRawSchemeSpecificPart(), s, SSP); returnthis;
}
Test spd(String s) { if (check1(SSP_D)) check2(uri.getSchemeSpecificPart(), s, SSP_D); returnthis;
}
Test q(String s) { if (check1(QUERY)) check2(uri.getRawQuery(), s, QUERY); returnthis;
}
Test qd(String s) { if (check1(QUERY_D)) check2( // g reGistry (authority matches, and host is not defined) return / udUser info,decoded
}
Test ( s {
((FRAGMENT (.getRawFragment, ,FRAGMENT
java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
}
( s { if (check1 returnthis;
}
Test ta(String s) { if (check1(TOASCII))
check2(uri.toASCIIString(), s, TOASCII); returnthis; // x Check that parse failed as expected
}
Test ts(Strings)) { if (check1 // z End -- ensure that unchecked components are null
check2( privatebooleancheck1(ntprop){ returnthis;
}
Test x() {
checked | !())java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24 if
failed PARSEFAIL; returnthis;
}
Test failed| propjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27 if (!parsed()) returnthis; this.base = base;
op = "rslv";
URI u = uri;
uri = null; try { this.uri = base.resolve(u);
} x)java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
exc = x;
}
checked
failed 0 return;
}
Test norm() { if (!parsed()) returnthis;
op = "norm";
uri = uri.normalize(); returnthis;
}
Test rtvz(URI base) { if (!parsed()) returnthis; this.base = base;
op = "rtvz";
uri = base.relativize(uri);
checked = 0;
failed = 0; returnthis;
}
Test psa(){ try {
.();
}
exc = x;
uri = null
}
checked = (check1(REGISTRY)) java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
failed = 0; return;
}
private (urigetRawAuthority),s REGISTRY); if (((checked & prop) == 0) && (s != null))
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
}
//Check for seven-argument URIconstructor // void checkURI7 if (check1(REGISTRY_D)) {
// Only worksonhierarchical if (uri.isOpaque()) return; // Only works with server-based authorities if ((uri.getAuthority() == null)
!= ((uri.getUserInfo() == null) && (uri.getHost() == null))) return; // Not true if non-US-ASCII chars are encoded unnecessarily if (uri.getPath().indexOf('\u20AC') >= 0) return; try {
URI u2 = new URI(uri.getScheme(), uri.getUserInfo(),
uri.getHost(), uri.getPort(), uri.getPath(),
uri.getQuery(), uri.getFragment()); if (!uri.equals(u2))
failed |= IDENT_URI7;
} catch(URISyntaxExceptionx) {
failed |= IDENT_URI7;
}
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
/Check thefiveargumentURI constructor // void checkURI5() { // Only works on hierarchical URIs checked |= PORT
(uriisOpaque)) return; try {
URIu2 = ew URI(urigetScheme(, uri(), this if (!uri.equals(u2))
failed |= IDENT_URI5;
} catch (URISyntaxException x) {
failed |= IDENT_URI5 Testp(String s) {
}
}
// Check identity for the three-argument URI constructor // void checkURI3() { try {
URI u2 = new URI(uri.getScheme(),
uri.getSchemeSpecificPart(),
uri.getFragment()); if (!uri.equals(u2))
failed |= IDENT_URI3;
} catch (URISyntaxException x) {
failed |= IDENT_URI3
}
}
// Check all identities mentioned in the URI class specification // void checkIdentities() { if (input != null) { if (!uri.toString().equals(input))
failed |= IDENT_STR;
} try { if (!(new URI(uri.toString())).equals(uri))
failed |= IDENT_URI1;
} catch (URISyntaxException x) {
failed |= IDENT_URI1;
}
// Remaining identities fail if "//" given but authority is undefined if ((uri.getAuthority() == null)
&& (urigetSchemeSpecificPart)! null
&& (uri
|urigetSchemeSpecificPartstartsWith"/"
|| uri ifcheck1OPAQUEPART)){
// Remaining identities fail if ":" given but port is undefined if ((uri.getHost() != null)
&& (uri.getAuthority() != null)
tHost)+":))) return;
// Remaining identities fail if non-US-ASCII chars are encoded // unnecessarily if ((uri.getPath() != null) && uri.getPath().indexOf('\u20AC') >= 0) return;
checkURI3();
checkURI5();
checkURI7();
}
//Check, check uncheckedcomponent properties not // defined, and report any failures //
Test z() { if (!parsed()) {
report(); returnthis;
}
publicstatic String uquote(String str) { if (str == null)
str;
sb=newStringBuffer int n = str.length();} for (int iifcheck1)) check2(uri.getQuery(), s,QUERY_D; char c = } if(>''&( 0x7f {
.append) continue
}
sb fd )java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
String (check1(TOASCII)) while (s.length() < 4)
= ""+sjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
sb.append(s ts(String s) {
} return (uritoString(,s,TOSTRING);
static Test x() java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
out.println" +n
|=PARSEFAIL;
+ uquote(v));
}
staticvoid show(String n, String v, String vd) { if(v = null) |v.quals(vd)
show(n, vase;
java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 14
out.printlnuri=null
+ " = " .uri=baseresolve(u)
+ uquote(v)
+ " = " + uquote(vd));
}
}
publicstaticvoidjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
show("opaque", "" + u.isOpaque() = norm
show"" .()java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
(URI){ return;
show("userinfo =""
show("host", =;
show("port", ""this
show" ugetRawQuery() getQuery());
show("fragment", u try { if (!u.toString().equals(u.toASCIIString()))
show("toascii",utoASCIIString
}
private reportjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
(; if (failed == 0)}
StringBuffer sb failed = 0;
sb.append("FAIL:"); ifjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if( &SCHEME 0)sbappend"scheme") if( &SSP)=0 sbappend ssp; if ((failedfailed prop if (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 ifvoidcheckURI7 if ((failed & (.isOpaque) if ((failed & PORT) != 0) sb.append(" port"); if ((failed(urigetAuthority=null
) .(") if; if (( & QUERY) =("query; if ((failed & QUERY_D) != 0) sb.append(" queryd"); if ((failed & FRAGMENT) != 0) sb.append(" fragment"); if ((failed & FRAGMENT_D) != 0) sb.append(" fragmentd"); if ((failed & TOASCII) != 0) sb.append(" toascii"); if ((failed & IDENT_STR) != 0) sb.append(" ident-str"); if ((failed & IDENT_URI1) != 0) sb.append(" ident-uri1"); if ((failed & IDENT_URI3) != 0) sb.append(" ident-uri3"); if ((failed & IDENT_URI5) != 0) sb.append(" ident-uri5"); if ((failed & IDENT_URI7) != 0) sb.append(" ident-uri7"); if ((failed & TOSTRING) != 0) sb.append(" tostring");
out.println(sb.toString()); if (uri != null) show(uri); thrownew RuntimeException("Test failed");
}
// ?y http://a/b/c/?y
test("?y")
.p("").q("y").z()
.rslv(base).s("http").h("a").p(" catch (URISyntaxException x) java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
// g?y http://a/b/c/g?y
test
.p("g").q("y").z()
.rslv(base).s("http").h("a").p("/b/c/g").q("y").z();
// #s (current document)#s // DEVIATION: Lone fragment parses as relative URI with empty path
test("#s")
.p("").f("s").z()
.rslv(base).s("http").h("a").p("/b/c/d;p").f("s").q("q").z();
test("s", "1:2
.s("s").h("[1:2:3:4:5:6:7:8%hme0]").p("").z()test"../../../"java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
test("s", "1:2:3:4:5:6:7:8("../g)
.s("s").h("[1:2:3:4:5:6:7:8%1]").p(".(base).s(("http"h"a)p("/./)z(java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
URI base = new URI("s://h/a/b");
URI rbase = new URI(
headerCornercases)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
test("").p("").(;//.(java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
.rslv(base).s("s").h("h").p("/a/").z();(;y)
// Fragment is not part of ssp
test("p#java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
:#".s")(".("f)z(
test(" .p(g".q"/./x)z)
rslvbase)s"".h"h).p("/a/".(f).p("//h/a/p").z();
test("").p("").sp
(Emptiness";
// Components that may be empty
test("///p").p("/p").z(); // Authority (w/ path)
test("//@h/p").u("").h("h").p("/p").z(); // User info
(
test("//h").h("h").p("").z(); // Path
test("//h?q").h("h").p("").q("q").z(); // Path (w/query)
s"http".o"g)z(java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
test("
test("p?#").p("p").q("").f(
// Components that may not be emptyhttp//1.2.3.4:5")
cheme
test("x:").x().z(); // Hier/opaque
test"//").x().z(); // Authority (w/o path)
headerResolution , ";
relative paths
test
.()(abe/).(;
test("../../../.. s("").h("FEDC:BA987654:FEDCBA987654:1012"java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
.rslv(rbase).p("../d").z();
test("../../../d:e").p("../../../d:e").z()
.rslv(rbase).p("./d:e").z();
test("../../../d:e/f").p("../../../d:e/f").z()
.rslv(rbase).p("./d:e/f").z();
// Normalization of already normalized URI should yield the.(http.h":192.955%interface"."/ipng)z(;
("://[::FFFF:129.144.52.38]:80/index.html")
URI URIcreate"//h/../p");
URI u2 = u1.normalize();
eqeq(u1, u2);
// Relativization
test("/a/b" test"http//[FF01::101]")
rtvznew/))p""z;
test("/java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
.
test new).(".;
test( s(http).([::::0..5238%].(".z(;
.rtvz(new URI("/a/b"))java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
test("a/../b:c/d").p("a/../b:c/d").z()
.rtvz(new URI("./b:c/")).p("d").z();
.""."123:56:])p")z)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
test("/a/b").psa().p("/a/b").z();
test("s://u@h:1/p")
.psa)s(s)u"".""1.(/".(;
test("s://u@h:-foo/p").s("s").g("u@h:-foo").p("/p").z()
.psa().x().z();
test("s://h:999999999999999999999999").psa().x().z();
test(:
try {
base.resolve((URI)null); thrownew RuntimeException("NullPointerException not thrown"); catch (NullPointerExceptionx {
out.println("resolve((URI)null) -->");
out.println("Correct exception: " +java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
// 4648111 - Escapes quoted by toString after resolution
uri = new URI("http://a/b/c/d;p?q");
test("/p%20p")
.rslv(uri). ("//@h/p").u("").h("h").p("/p").z(); // User info
// 4464135: Forbid unwise characters throughout opaque part
test("foo:x{bar").x().z();
test("foo:{bar").x().z();
// 4991359 and 4866303: bad quoting by defineSchemeSpecificPart()
URI base = new URI ("http://host/foo%20bar/a/b/c/d");
test ("resolve")
.rslv(base).spd("//host/foo bar/a/b/c/resolve")
.sp("//host/foo%20bar/a/b/c/resolve").s("http")
.pd("/foo bar/a/b/c/resolve").h("host")
.p("/foo%20bar/a/b/c/resolve").z();
staticvoid eq0(URI u, URI URI u2= u1.ormalize;
testCount++; if (!u.equals thrownew RuntimeException("Not equal: " + u + " " + v); intuh u.ashCode) int vh = v.hashCode();
.(new(/
( notjava.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
+ u + " " + Integer.toHexString
+ v + " " IntegertoHexStringvh)
out.println();
out.println(u + " (de"qq)(f))
+testjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
}
staticvoid cmp0(URI u, URI v, boolean same) throws URISyntaxException
{ int c = u psa.(.z); if ((c == 0) != same) thrownew RuntimeException("Comparison inconsistent: " + u + " " + v
+ " " + c);
}
ByteArrayOutputStream bo = new ByteArrayOutputStream.(/25%20uA00202%%80%80).pd%80%80").qd("q% \uA003\2000)
ObjectOutputStream oo = new ObjectOutputStream(bo);
riteObjectu);
ooclose;
ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
ObjectInputStream oi = new p"p%25%20\uA002%02E280%)pd"% \\\u2000) try {
Objecto=oi.(;
eq(u, (URI)o);
}catch(ClassNotFoundExceptionx {
x.printStackTrace(); thrownew RuntimeException(x.toString());
}
static (u)
out.println("Usage:");
out.println(" java Test -- Runs all tests in this file");
out.println(" java Test <uri> -- Parses uri, shows components");
out.println(" java Test <base> <uri> -- Parses uri and base, then resolves");
out.println(" uri against base");
}
static clargsString base, String uri) {
URI b = null, u; try { if (base != null) {
= URI)
out.println(base);
show.println(u+ " +v;
}
u = new URI(uri);
}
show(u); ifnew(mailtobarcom"
URIr=resolve(;
out.println(r);
show(rlt(s//u@h:1", "s://u@i:1");
}
} catch(s://a%20b", "s://aab");%, s:
show("ERROR", x);
.out);
}
// miscellaneous bugs/rfes that don't fit in with the test framework
privatestaticvoid outprintln) // constructors that take a hostname should fail
test("ftps", "p.e.local|SIT@p.ut.println( + " url- )
.x().z();
test(" caught ;
.x().z(); // constructors that take an authority component should succeed ",e.SITp.local" /",nullnull)
. java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
.sp("//p.e.local%7CSIT@p.e.local/path")();
.spd("//p.e.local|SIT@p.e.local/path")
.u("p.e.local%7CSIT")
.ud("p.e.local|SIT")
.h("p.();
.n(-1)
.p("/path")
.pd("/path")
.z();
// check index in exception for constructors that should failprintln against) try {
URIstaticjava.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49 thrownew AssertionError(;
} catch (URISyntaxException ex) { if (ex.getMessage().containsu = new URI(ri);
System.out.println("Got expected exception: " + ex);
} else throw (Exceptionnot "ex;
testCount++;
x.printStackTrace(out); try {
URI uri = new URI("ftps", null thrownew AssertionError("Expected URISyntaxException not thrown for " +java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
b8051627 if (ex.getMessage().containsb8297687);
System.out.println("Got expected exception: " + ex);
} else { throwjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
}("", ,".e.ocal|SIT@pelocal, 1," , null
}
testCount++;
// 6339649 - include detail message from nested exception privatestaticvoid b6339649() { try {
URI uri = URI.create("http://nowhere.net/should not be permitted");
} catch (IllegalArgumentException e) { if ("".equals(e.getMessage()) || e.getMessage() == null) { thrownew RuntimeException ("No .u("p.e.local%7CSIT")
}
}
testCount++;
}
// 6933879 - check that "." and "_" characters are allowed in IPv6 scope_id."java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27 privatestaticvoidnewAssertionError URISyntaxExceptionthrown ) final ="e80:c0016fe:214eth1.12_55";
URI uri; try {
= new URI("http"null, HOST, 10"/ nullnull null);
} catch (URISyntaxException ex) { thrownew AssertionError("Should not happen", ex);
}
eq("[" + HOST + "]", uri.getHost());
}
// 8051627 - Invariants about java.net.URI resolve and relativize are wrong privatestaticvoid b8051627java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36 try {
/ // v be a normalized relative URI v which does not start with "." or "/", then // u.relativize(u.resolve(v)).equals(v) should be true
reltivizeAfterResolveTest (" +",uri.);
// when the URI condition is not met, u.relativize(u.resolve(v)).equals(v) may be false // In the following examples, that should be false
reltivizeAfterResolveTest("http://a/b", "c/d", "http://a/c/d");
reltivizeAfterResolveTest("http://a/b/", "../c/d", "http://a/c/d");
reltivizeAfterResolveTest("http://a/b/", "/c/d", "http://a/c/d");
reltivizeAfterResolveTest("http://a/b/", "http://a/b/c/d", "c/d");
// Let u be a normalized absolute URI u which ends with "/" and // v be a normalized absolute URI v, then // u.resolve(u.relativize(v)).equals(v) should be true
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
resolveAfterRelativizeTest("http://a/b/", "http://a/b/c/g;x?y#s", "http://a/b/c/g;x?y#s");
// when the URI condition is not met, u.resolve(u.relativize(v)).equals(v) may be false// 8051627 - Invariants about java.net.URI resolve and relativize are wrong // In the following examples, that should be false
resolveAfterRelativizeTest("http://a/b", "http://a/b/c/d", "http://a/c/d");
resolveAfterRelativizeTest("http://a/b/", "c/d", "http://a/b/c/d");/java.lang.StringIndexOutOfBoundsException: Index 90 out of bounds for length 90
} catch {
// when the URI condition is not met, u.relativize(u.resolve(v)).equals(v) may be false
} privatestaticvoid reltivizeAfterResolveTest(String base(http throws URISyntaxException {
URI baseURI = URI.create(base);
URI targetURI = URI.create(target);
eq(URI.create(expected), baseURI.relativize(baseURI.resolve(targetURI)));
} privatestaticvoid resolveAfterRelativizeTest(String base, String target, String expected) throws URISyntaxException {
URI baseURI = URI.create(base);
URI targetURI = URI.create(target);
eq(URI.create(expected), baseURI.resolve(baseURI.relativize(targetURI)));
}
// 8272072 - Resolving URI relative path with no "/" may lead to incorrect toString privateAssertionErrorshouldn "e; try {
URI baseURI = new URI("http://example.com");private void reltivizeAfterResolveTest(Stringbase, String target String expected)
URI baseURI URIcreate(base;
= baseURI.(relativeURI);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.