Fix URI var encoding issue with '$'

When expanding and strictly encoding URI variables, there is no need to
quote `/` and `$` which will be encoded anyway.

Issue: SPR-17168
This commit is contained in:
Rossen Stoyanchev
2018-08-13 11:51:18 +03:00
parent 430065c31d
commit 99f0129711
2 changed files with 13 additions and 8 deletions

View File

@@ -243,7 +243,7 @@ public abstract class UriComponents implements Serializable {
@Nullable
static String expandUriComponent(@Nullable String source, UriTemplateVariables uriVariables,
@Nullable UnaryOperator<String> variableEncoder) {
@Nullable UnaryOperator<String> encoder) {
if (source == null) {
return null;
@@ -258,15 +258,14 @@ public abstract class UriComponents implements Serializable {
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
String match = matcher.group(1);
String variableName = getVariableName(match);
Object variablesValue = uriVariables.getValue(variableName);
if (UriTemplateVariables.SKIP_VALUE.equals(variablesValue)) {
String varName = getVariableName(match);
Object varValue = uriVariables.getValue(varName);
if (UriTemplateVariables.SKIP_VALUE.equals(varValue)) {
continue;
}
String formattedValue = getVariableValueAsString(variablesValue);
formattedValue = Matcher.quoteReplacement(formattedValue);
formattedValue = variableEncoder != null ? variableEncoder.apply(formattedValue) : formattedValue;
matcher.appendReplacement(sb, formattedValue);
String formatted = getVariableValueAsString(varValue);
formatted = encoder != null ? encoder.apply(formatted) : Matcher.quoteReplacement(formatted);
matcher.appendReplacement(sb, formatted);
}
matcher.appendTail(sb);
return sb.toString();