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:
Brian Clozel
2015-05-06 14:54:18 +02:00
parent 9eb3518583
commit 8b545f47bd
2 changed files with 22 additions and 3 deletions

View File

@@ -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");