Skip to content

Commit

Permalink
Do not decode URL encoding while setting up RequestTemplate (#2228)
Browse files Browse the repository at this point in the history
* Do not decode URL encoding while setting up RequestTemplate (#2227)

* Add unit test for preserving URL encoding in RequestTemplate (#2227)
  • Loading branch information
Breina authored Nov 8, 2023
1 parent 0112f65 commit 3c4e713
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/java/feign/RequestTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ public RequestTemplate target(String target) {
}

/* strip the query string */
this.target = targetUri.getScheme() + "://" + targetUri.getAuthority() + targetUri.getPath();
this.target =
targetUri.getScheme() + "://" + targetUri.getRawAuthority() + targetUri.getRawPath();
if (targetUri.getFragment() != null) {
this.fragment = "#" + targetUri.getFragment();
}
Expand Down
8 changes: 8 additions & 0 deletions core/src/test/java/feign/RequestTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,14 @@ public void fragmentShouldNotBeEncodedInTarget() {
assertThat(template.url()).isEqualTo("https://example.com/path?key1=value1#fragment");
}

@Test
public void urlEncodingRemainsInPlace() {
RequestTemplate template =
new RequestTemplate().method(HttpMethod.GET).target("https://exa%23mple.com/path%7Cpath");

assertThat(template.url()).isEqualTo("https://exa%23mple.com/path%7Cpath");
}

@Test
public void slashShouldNotBeAppendedForMatrixParams() {
RequestTemplate template =
Expand Down

0 comments on commit 3c4e713

Please sign in to comment.