Fix remote context handling in UrlTag
Prior to this change, the `UrlTag` would simply append the remote context and the path value in case of a context relative URL. The following code snippet would output "//foo": ``` <spring:url value="/foo" context="/" /> ``` This change now removes trailing slashes in remote context to avoid this. Issue: SPR-12782
This commit is contained in:
parent
9eb3518583
commit
8b545f47bd
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -208,10 +208,15 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
|
||||||
if (this.context == null) {
|
if (this.context == null) {
|
||||||
url.append(request.getContextPath());
|
url.append(request.getContextPath());
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if(this.context.endsWith("/")) {
|
||||||
|
url.append(this.context.substring(0, this.context.length() - 1));
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
url.append(this.context);
|
url.append(this.context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (this.type != UrlType.RELATIVE && this.type != UrlType.ABSOLUTE && !this.value.startsWith("/")) {
|
if (this.type != UrlType.RELATIVE && this.type != UrlType.ABSOLUTE && !this.value.startsWith("/")) {
|
||||||
url.append("/");
|
url.append("/");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -528,6 +528,20 @@ public class UrlTagTests extends AbstractTagTests {
|
||||||
assertEquals("/some-other-context/url/path", uri);
|
assertEquals("/some-other-context/url/path", uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCreateUrlRemoteContextSingleSlash() throws JspException {
|
||||||
|
((MockHttpServletRequest) context.getRequest())
|
||||||
|
.setContextPath("/app-context");
|
||||||
|
|
||||||
|
tag.setValue("/url/path");
|
||||||
|
tag.setContext("/");
|
||||||
|
|
||||||
|
tag.doStartTag();
|
||||||
|
|
||||||
|
String uri = invokeCreateUrl(tag);
|
||||||
|
|
||||||
|
assertEquals("/url/path", uri);
|
||||||
|
}
|
||||||
|
|
||||||
public void testCreateUrlWithParams() throws JspException {
|
public void testCreateUrlWithParams() throws JspException {
|
||||||
tag.setValue("url/path");
|
tag.setValue("url/path");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue