Last active
December 11, 2015 21:38
-
-
Save wookayin/4663472 to your computer and use it in GitHub Desktop.
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 static org.hamcrest.CoreMatchers.*; | |
import static org.junit.Assert.*; | |
import java.net.URI; | |
import org.junit.Test; | |
import org.springframework.web.util.UriComponentsBuilder; | |
public class URIComponentsCannotHandleRelativeUri { | |
URI baseUri = new URI("http://zum.com/a/b/c/d/e.html"); | |
@Test | |
public void relativeUri_usingConstructor() throws Exception { | |
URI relativeUri = new URI("../test.png"); | |
assertThat(relativeUri.getPath(), equalTo("../test.png")); | |
assertThat(baseUri.resolve(relativeUri), equalTo(new URI("http://zum.com/a/b/c/test.png"))); | |
} | |
@Test | |
public void relativeUri_withUriComponentsBuilder() throws Exception { | |
URI relativeUri = UriComponentsBuilder.fromUriString("../test.png").build().toUri(); | |
// fails, but was '/../test.png' | |
assertThat(relativeUri.getPath(), equalTo("../test.png")); | |
// also fails, but was 'http://zum.com/../test.png' | |
assertThat(baseUri.resolve(relativeUri), equalTo(new URI("http://zum.com/a/b/c/test.png"))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment