Skip to content

Instantly share code, notes, and snippets.

@wookayin
Last active December 11, 2015 21:38
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 wookayin/4663472 to your computer and use it in GitHub Desktop.
Save wookayin/4663472 to your computer and use it in GitHub Desktop.
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