Skip to content

Instantly share code, notes, and snippets.

@simon04
Created August 21, 2020 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simon04/1cce1e68e3eba9125dd26de058d5fb2a to your computer and use it in GitHub Desktop.
Save simon04/1cce1e68e3eba9125dd26de058d5fb2a to your computer and use it in GitHub Desktop.
Java URI copy constructor

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.

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/
}
}
@simon04
Copy link
Author

simon04 commented Aug 24, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment