Using the URI copy constructor on an URI where the userinfo part contains a percent-escaped colon (U+003A as %3A
) produces a different result.
Created
August 21, 2020 09:11
-
-
Save simon04/1cce1e68e3eba9125dd26de058d5fb2a to your computer and use it in GitHub Desktop.
Java URI copy constructor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Assert; | |
import org.junit.jupiter.api.Test; | |
import java.net.URI; | |
import java.net.URISyntaxException; | |
public class URITest { | |
@Test | |
void test() throws URISyntaxException { | |
URI u = new URI("http://user%3Acolon:[email protected]/"); | |
URI copy = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), u.getQuery(), u.getFragment()); | |
Assert.assertEquals(u, copy); | |
// java.lang.AssertionError: expected:<http://user%3Acolon:[email protected]/> but was:<http://user:colon:[email protected]/> | |
// Expected :http://user%3Acolon:[email protected]/ | |
// Actual :http://user:colon:[email protected]/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OpenJDK bug report: https://bugs.openjdk.java.net/browse/JDK-8252216