Skip to content

Commit

Permalink
Fix issue with encoded params in UriComponentsBuilder
Browse files Browse the repository at this point in the history
The fromUri method of UriComponentsBuilder used uri.getXxx() methods,
which decode the URI parts causing URI parsing issues. The same method
now uses uri.getRawXxx().

Issue: SPR-9317
  • Loading branch information
rstoyanchev committed May 1, 2012
1 parent ae9549a commit a33fe6f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Expand Up @@ -260,24 +260,24 @@ public UriComponentsBuilder uri(URI uri) {

this.scheme = uri.getScheme();

if (uri.getUserInfo() != null) {
this.userInfo = uri.getUserInfo();
if (uri.getRawUserInfo() != null) {
this.userInfo = uri.getRawUserInfo();
}
if (uri.getHost() != null) {
this.host = uri.getHost();
}
if (uri.getPort() != -1) {
this.port = uri.getPort();
}
if (StringUtils.hasLength(uri.getPath())) {
this.pathBuilder = new FullPathComponentBuilder(uri.getPath());
if (StringUtils.hasLength(uri.getRawPath())) {
this.pathBuilder = new FullPathComponentBuilder(uri.getRawPath());
}
if (StringUtils.hasLength(uri.getQuery())) {
if (StringUtils.hasLength(uri.getRawQuery())) {
this.queryParams.clear();
query(uri.getQuery());
query(uri.getRawQuery());
}
if (uri.getFragment() != null) {
this.fragment = uri.getFragment();
if (uri.getRawFragment() != null) {
this.fragment = uri.getRawFragment();
}
return this;
}
Expand Down
Expand Up @@ -76,6 +76,17 @@ public void fromUri() throws URISyntaxException {
assertEquals("Invalid result URI", uri, result.toUri());
}

// SPR-9317

@Test
public void fromUriEncodedQuery() throws URISyntaxException {
URI uri = new URI("http://www.example.org/?param=aGVsbG9Xb3JsZA%3D%3D");
String fromUri = UriComponentsBuilder.fromUri(uri).build().getQueryParams().get("param").get(0);
String fromUriString = UriComponentsBuilder.fromUriString(uri.toString()).build().getQueryParams().get("param").get(0);

assertEquals(fromUri, fromUriString);
}

@Test
public void fromUriString() {
UriComponents result = UriComponentsBuilder.fromUriString("http://www.ietf.org/rfc/rfc3986.txt").build();
Expand Down
1 change: 1 addition & 0 deletions src/dist/changelog.txt
Expand Up @@ -12,6 +12,7 @@ Changes in version 3.2 M1
* fix concurrency issue in AnnotationMethodHandlerExceptionResolver
* fix case-sensitivity issue with some containers on access to 'Content-Disposition' header
* add Servlet 3.0 based async support
* fix issue with encoded params in UriComponentsBuilder

Changes in version 3.1.1 (2012-02-16)
-------------------------------------
Expand Down

0 comments on commit a33fe6f

Please sign in to comment.