Skip to content

Commit

Permalink
Replace Existing Continue Parameter
Browse files Browse the repository at this point in the history
Closes gh-13438
  • Loading branch information
jzheaux committed Jul 10, 2023
1 parent 8895a66 commit 40d6174
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.security.web.util.UrlUtils;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.web.util.UriComponentsBuilder;

/**
* Represents central information from a {@code HttpServletRequest}.
Expand Down Expand Up @@ -372,10 +373,8 @@ private static String createQueryString(String queryString, String matchingReque
if (queryString == null || queryString.length() == 0) {
return matchingRequestParameterName;
}
if (queryString.endsWith("&")) {
return queryString + matchingRequestParameterName;
}
return queryString + "&" + matchingRequestParameterName;
return UriComponentsBuilder.newInstance().query(queryString).replaceQueryParam(matchingRequestParameterName)
.queryParam(matchingRequestParameterName).build().getQuery();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,14 @@ public void getRedirectUrlWhenQueryDoesNotEndAmpersandAndMatchingRequestParamete
assertThat(new URL(savedRequest.getRedirectUrl())).hasQuery("foo=bar&success");
}

// gh-13438
@Test
public void getRedirectUrlWhenQueryAlreadyHasSuccessThenDoesNotAdd() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setQueryString("foo=bar&success");
DefaultSavedRequest savedRequest = new DefaultSavedRequest(request, new MockPortResolver(8080, 8443),
"success");
assertThat(savedRequest.getRedirectUrl()).contains("foo=bar&success");
}

}

0 comments on commit 40d6174

Please sign in to comment.