Use URLDecoder for query params in WebFlux

Issue: SPR-15860
This commit is contained in:
Rossen Stoyanchev
2017-08-16 13:34:31 +02:00
parent 8b7a670821
commit 645e3492db
3 changed files with 21 additions and 5 deletions

View File

@@ -16,11 +16,15 @@
package org.springframework.http.server.reactive;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.net.URLDecoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.RequestPath;
@@ -38,6 +42,8 @@ import org.springframework.util.StringUtils;
*/
public abstract class AbstractServerHttpRequest implements ServerHttpRequest {
private static final Log logger = LogFactory.getLog(ServerHttpRequest.class);
private static final Pattern QUERY_PATTERN = Pattern.compile("([^&=]+)(=?)([^&]+)?");
@@ -113,8 +119,18 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest {
return queryParams;
}
@SuppressWarnings("deprecation")
private String decodeQueryParam(String value) {
return StringUtils.uriDecode(value, StandardCharsets.UTF_8);
try {
return URLDecoder.decode(value, "UTF-8");
}
catch (UnsupportedEncodingException ex) {
if (logger.isWarnEnabled()) {
logger.warn("Could not decode query param [" + value + "] as 'UTF-8'. " +
"Falling back on default encoding; exception message: " + ex.getMessage());
}
return URLDecoder.decode(value);
}
}
@Override