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.
Java URI copy constructor
This file contains 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:password@example.com/"); | |
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:password@example.com/> but was:<http://user:colon:password@example.com/> | |
// Expected :http://user%3Acolon:password@example.com/ | |
// Actual :http://user:colon:password@example.com/ | |
} | |
} |
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