Skip to content

Commit fe95cf5

Browse files
committed
eliminate double escaping in UriPage (fixes gooddata#428)
1 parent eebbe89 commit fe95cf5

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/main/java/com/gooddata/collections/UriPage.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
import org.springframework.web.util.UriComponents;
99
import org.springframework.web.util.UriComponentsBuilder;
10+
import org.springframework.web.util.UriUtils;
1011

12+
import java.io.UnsupportedEncodingException;
1113
import java.net.URI;
1214
import java.util.List;
1315
import java.util.Map.Entry;
@@ -27,7 +29,11 @@ class UriPage implements Page {
2729
* @param pageUri page URI
2830
*/
2931
public UriPage(final String pageUri) {
30-
this.pageUri = UriComponentsBuilder.fromUriString(notNull(pageUri, "pageUri")).build();
32+
try {
33+
this.pageUri = UriComponentsBuilder.fromUriString(UriUtils.decode(notNull(pageUri, "pageUri"), "UTF-8")).build();
34+
} catch (final UnsupportedEncodingException e) {
35+
throw new IllegalStateException(e);
36+
}
3137
}
3238

3339
/**

src/test/java/com/gooddata/collections/UriPageTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,10 @@ public void testIdempotency() throws Exception {
6363
assertThat(components.getQueryParams(), hasEntry("offset", singletonList("god")));
6464
assertThat(components.getQueryParams(), hasEntry("limit", singletonList("10")));
6565
}
66+
67+
@Test
68+
public void testEncoding() throws Exception {
69+
final UriPage uri = new UriPage("uri?test=foo%20bar");
70+
assertThat(uri.getPageUri(null).toString(), is("uri?test=foo%20bar"));
71+
}
6672
}

0 commit comments

Comments
 (0)