FULL PRODUCT VERSION :
openjdk version "1.8.0_71"
OpenJDK Runtime Environment (build 1.8.0_71-b15)
OpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux <removed> 4.3.4-300.fc23.x86_64 #1 SMP Mon Jan 25 13:39:23 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
The java.net.URI documentation explain on its normalize method javadoc the treatment of path components that include a colon character. First trying to create a new URI with only a path component with a colon on result in an absolute URL with an scheme based on the path string
new URI(null,null,"a:b",null).isAbsolute()
return true.
new URI(null,null,"a:b",null).getScheme()
return "a", it should return null and be a relative URI
If try to use relativize method to get a"a:b" as a relative URI
URI root = new URI("file", null, "/", null);
URI withPath = new URI("file",null,"/./a:b",null);
URI rel = root.relativize(withPath);
You get a relative URI with a path component with a first segment that contains a colon character
rel.isAbsolute()
return false, but normalize()
rel.normalize()
doesn't prepend the "." segment as the Javadoc say
So in summary,
1) Instatiating an URI with only a path component parses an scheme when the first segment of the path contains a colo character
2) Normalize does not prepend the segment "." as the third step of the javadoc say
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached test case with assertions enabled
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No assertion should fail
ACTUAL -
Assertion are triggered, the colon character is being detected as a scheme separator when is is used on a path component
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] args) throws Exception {
URI withColonURI = new URI(null, null, "a:b", null);
assert !(withColonURI.isAbsolute()) : "Should be relative";
assert withColonURI.getScheme() == null : "Should not have a scheme";
URI root = new URI("file", null, "/", null);
URI withPath = new URI("file", null, "/a:b", null);
URI rel = root.relativize(withPath);
assert !rel.isAbsolute() : "Should be relative";
assert rel.normalize().toASCIIString().startsWith("./") : "Normalization should prepend \".\" segment";
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
For calling
new URI(null, null, "a:b", null)
always prepend the "." segment
new URI(null, null, "./a:b", null)
openjdk version "1.8.0_71"
OpenJDK Runtime Environment (build 1.8.0_71-b15)
OpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux <removed> 4.3.4-300.fc23.x86_64 #1 SMP Mon Jan 25 13:39:23 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
The java.net.URI documentation explain on its normalize method javadoc the treatment of path components that include a colon character. First trying to create a new URI with only a path component with a colon on result in an absolute URL with an scheme based on the path string
new URI(null,null,"a:b",null).isAbsolute()
return true.
new URI(null,null,"a:b",null).getScheme()
return "a", it should return null and be a relative URI
If try to use relativize method to get a"a:b" as a relative URI
URI root = new URI("file", null, "/", null);
URI withPath = new URI("file",null,"/./a:b",null);
URI rel = root.relativize(withPath);
You get a relative URI with a path component with a first segment that contains a colon character
rel.isAbsolute()
return false, but normalize()
rel.normalize()
doesn't prepend the "." segment as the Javadoc say
So in summary,
1) Instatiating an URI with only a path component parses an scheme when the first segment of the path contains a colo character
2) Normalize does not prepend the segment "." as the third step of the javadoc say
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached test case with assertions enabled
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No assertion should fail
ACTUAL -
Assertion are triggered, the colon character is being detected as a scheme separator when is is used on a path component
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] args) throws Exception {
URI withColonURI = new URI(null, null, "a:b", null);
assert !(withColonURI.isAbsolute()) : "Should be relative";
assert withColonURI.getScheme() == null : "Should not have a scheme";
URI root = new URI("file", null, "/", null);
URI withPath = new URI("file", null, "/a:b", null);
URI rel = root.relativize(withPath);
assert !rel.isAbsolute() : "Should be relative";
assert rel.normalize().toASCIIString().startsWith("./") : "Normalization should prepend \".\" segment";
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
For calling
new URI(null, null, "a:b", null)
always prepend the "." segment
new URI(null, null, "./a:b", null)