Avoid regex pattern matching for simple String replacement steps

Issue: SPR-17279
This commit is contained in:
Juergen Hoeller
2018-09-17 14:22:19 +02:00
parent cc87fbcb7f
commit 34663300a6
13 changed files with 61 additions and 30 deletions

View File

@@ -38,7 +38,7 @@ import org.springframework.web.util.TagUtils;
import org.springframework.web.util.UriUtils;
/**
* The {@code <url>} tag creates URLs. Modeled after the JSTL c:url tag with
* The {@code <url>} tag creates URLs. Modeled after the JSTL {@code c:url} tag with
* backwards compatibility in mind.
*
* <p>Enhancements to the JSTL functionality include:
@@ -361,7 +361,8 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
usedParams.add(param.getName());
String value = param.getValue();
try {
uri = uri.replace(template, (value != null ? UriUtils.encodePath(value, encoding) : ""));
uri = StringUtils.replace(uri, template,
(value != null ? UriUtils.encodePath(value, encoding) : ""));
}
catch (UnsupportedCharsetException ex) {
throw new JspException(ex);
@@ -373,7 +374,7 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
usedParams.add(param.getName());
String value = param.getValue();
try {
uri = uri.replace(template,
uri = StringUtils.replace(uri, template,
(value != null ? UriUtils.encodePathSegment(param.getValue(), encoding) : ""));
}
catch (UnsupportedCharsetException ex) {

View File

@@ -194,7 +194,7 @@ public class GroovyMarkupConfigurer extends TemplateConfiguration
protected URL resolveTemplate(ClassLoader classLoader, String templatePath) throws IOException {
MarkupTemplateEngine.TemplateResource resource = MarkupTemplateEngine.TemplateResource.parse(templatePath);
Locale locale = LocaleContextHolder.getLocale();
URL url = classLoader.getResource(resource.withLocale(locale.toString().replace("-", "_")).toString());
URL url = classLoader.getResource(resource.withLocale(StringUtils.replace(locale.toString(), "-", "_")).toString());
if (url == null) {
url = classLoader.getResource(resource.withLocale(locale.getLanguage()).toString());
}