diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java index c8713386c6c..6e8aaff12b7 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java @@ -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"); * you may not use this file except in compliance with the License. @@ -209,7 +209,12 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware { url.append(request.getContextPath()); } else { - url.append(this.context); + if(this.context.endsWith("/")) { + url.append(this.context.substring(0, this.context.length() - 1)); + } + else { + url.append(this.context); + } } } if (this.type != UrlType.RELATIVE && this.type != UrlType.ABSOLUTE && !this.value.startsWith("/")) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/UrlTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/UrlTagTests.java index 0ce1d6adc33..15ce4126775 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/UrlTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/UrlTagTests.java @@ -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"); * 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); } + 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 { tag.setValue("url/path");