Support path segment URI var expansion in UrlTag

Before this change UrlTag expanded URI vars and encoded them using
UriUtils.encodePath.

This change makes it possible to expand using
UriUtils.encodePathSegment, which means a "/" is encoded as "%2F".

To expand with path segment semantics, prefix the URI var name "/":

<spring:url value="/url/path/{/var}">
    <spring:param name="var" value="my/Id" />
</spring:url>

Issue: SPR-11401
This commit is contained in:
Rossen Stoyanchev
2014-05-06 19:41:17 -04:00
parent 9d479feadd
commit 426b77b834
2 changed files with 48 additions and 0 deletions

View File

@@ -295,6 +295,18 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
throw new JspException(ex);
}
}
else {
template = URL_TEMPLATE_DELIMITER_PREFIX + "/" + param.getName() + URL_TEMPLATE_DELIMITER_SUFFIX;
if (uri.contains(template)) {
usedParams.add(param.getName());
try {
uri = uri.replace(template, UriUtils.encodePathSegment(param.getValue(), encoding));
}
catch (UnsupportedEncodingException ex) {
throw new JspException(ex);
}
}
}
}
return uri;
}