Fix UriComponentsBuilder.fromUriString parsing error
This commit fixes cases where part of the URI was mistaken for the
userinfo when:
* the URI did not contain any path
* the query string contained the "@"
Issue: SPR-11970
(cherry picked from commit a4484bb)
This commit is contained in:
committed by
Juergen Hoeller
parent
10a039000b
commit
a3a76d8c15
@@ -26,6 +26,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
@@ -216,6 +217,17 @@ public class UriComponentsBuilderTests {
|
||||
assertEquals("[::192.168.1.1]", resultIPv4compatible.getHost());
|
||||
}
|
||||
|
||||
// SPR-11970
|
||||
|
||||
@Test
|
||||
public void fromUriStringNoPathWithReservedCharInQuery() {
|
||||
UriComponents result = UriComponentsBuilder.fromUriString("http://example.com?foo=bar@baz").build();
|
||||
assertTrue(StringUtils.isEmpty(result.getUserInfo()));
|
||||
assertEquals("example.com", result.getHost());
|
||||
assertTrue(result.getQueryParams().containsKey("foo"));
|
||||
assertEquals("bar@baz", result.getQueryParams().getFirst("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void path() throws URISyntaxException {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar");
|
||||
|
||||
Reference in New Issue
Block a user