Skip to content

Commit bc0b129

Browse files
author
merit\rembjo0
committed
Adds # support in HttpRequest query string parsing
HttpRequest.getEncodedParameter() will now return the corrent value for the last parameter before the #. Example: foo=bar#ignore now returns 'bar' and not 'bar#ignore' for the 'foo' parameter.
1 parent b93d1df commit bc0b129

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

core/src/main/java/com/onelogin/saml2/http/HttpRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public Map<String, List<String>> getParameters() {
152152
* @return the first value for the parameter, or null
153153
*/
154154
public String getEncodedParameter(String name) {
155-
Matcher matcher = Pattern.compile(Pattern.quote(name) + "=([^&]+)").matcher(queryString);
155+
Matcher matcher = Pattern.compile(Pattern.quote(name) + "=([^&#]+)").matcher(queryString);
156156
if (matcher.find()) {
157157
return matcher.group(1);
158158
} else {

core/src/test/java/com/onelogin/saml2/http/HttpRequestTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ public void testGetEncodedParameter_handlesMultipleValuesOnQueryString() throws
142142
assertThat(request.getEncodedParameter("k3"), equalTo("v3"));
143143
}
144144

145+
@Test
146+
public void testGetEncodedParameter_stopsAtUrlFragment() throws Exception {
147+
final String url = "url";
148+
final String queryString = "first=&foo=bar#ignore";
149+
150+
final HttpRequest request = new HttpRequest(url, queryString);
151+
152+
assertThat(request.getEncodedParameter("foo"), equalTo("bar"));
153+
}
154+
145155
@Test
146156
public void testGetEncodedParameter_withDefault_usesDefaultWhenParameterMissing() throws Exception {
147157
final String url = "url";

0 commit comments

Comments
 (0)