Revert change to support {/...} var syntax

Issue: SPR-12750
This commit is contained in:
Rossen Stoyanchev
2015-05-14 10:06:33 -04:00
parent e843bcc725
commit 2c408b7069
5 changed files with 13 additions and 235 deletions

View File

@@ -16,13 +16,8 @@
package org.springframework.web.util;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.net.URI;
import java.net.URISyntaxException;
@@ -239,24 +234,6 @@ public class UriComponentsBuilderTests {
assertEquals("bar@baz", result.getQueryParams().getFirst("foo"));
}
//SPR-12750
@Test
public void fromUriStringWithSlashPrefixedVariable() {
UriComponents result = UriComponentsBuilder.fromUriString(
"http://example.com/part1/{/part2}/{var1}/url/{/urlvar}?foo=bar@baz&bar={barvalue}")
.build();
assertTrue(StringUtils.isEmpty(result.getUserInfo()));
assertEquals("example.com", result.getHost());
assertEquals("/part1/{/part2}/{var1}/url/{/urlvar}", result.getPath());
assertEquals(Arrays.asList("part1", "{/part2}", "{var1}", "url", "{/urlvar}"),
result.getPathSegments());
assertTrue(result.getQueryParams().containsKey("foo"));
assertEquals("bar@baz", result.getQueryParams().getFirst("foo"));
assertTrue(result.getQueryParams().containsKey("bar"));
assertEquals("{barvalue}", result.getQueryParams().getFirst("bar"));
}
@Test
public void fromHttpRequest() throws URISyntaxException {
MockHttpServletRequest request = new MockHttpServletRequest();

View File

@@ -30,8 +30,6 @@ import java.util.Arrays;
import org.junit.Test;
import org.springframework.web.util.HierarchicalUriComponents.FullPathComponent;
/**
* @author Arjen Poutsma
* @author Phillip Webb
@@ -167,49 +165,4 @@ public class UriComponentsTests {
assertThat(uriComponents1, not(equalTo(uriComponents3)));
}
@Test
public void partialPath() throws Exception {
FullPathComponent l;
l = new FullPathComponent("x");
assertEquals(1, l.getPartialPaths().size());
assertEquals("x", l.getPartialPaths().get(0).value);
assertEquals(HierarchicalUriComponents.Type.PATH, l.getPartialPaths().get(0).type);
l = new FullPathComponent("/foo");
assertEquals(1, l.getPartialPaths().size());
assertEquals("/foo", l.getPartialPaths().get(0).value);
assertEquals(HierarchicalUriComponents.Type.PATH, l.getPartialPaths().get(0).type);
l = new FullPathComponent("{/foo}");
assertEquals(1, l.getPartialPaths().size());
assertEquals("{/foo}", l.getPartialPaths().get(0).value);
assertEquals(HierarchicalUriComponents.Type.PATH_SEGMENT, l.getPartialPaths().get(0).type);
l = new FullPathComponent("/foo{/bar}");
assertEquals(2, l.getPartialPaths().size());
assertEquals("/foo", l.getPartialPaths().get(0).value);
assertEquals(HierarchicalUriComponents.Type.PATH, l.getPartialPaths().get(0).type);
assertEquals("{/bar}", l.getPartialPaths().get(1).value);
assertEquals(HierarchicalUriComponents.Type.PATH_SEGMENT, l.getPartialPaths().get(1).type);
l = new FullPathComponent("{/foo}{/bar}");
assertEquals(2, l.getPartialPaths().size());
assertEquals("{/foo}", l.getPartialPaths().get(0).value);
assertEquals(HierarchicalUriComponents.Type.PATH_SEGMENT, l.getPartialPaths().get(0).type);
assertEquals("{/bar}", l.getPartialPaths().get(1).value);
assertEquals(HierarchicalUriComponents.Type.PATH_SEGMENT, l.getPartialPaths().get(1).type);
l = new FullPathComponent("foo{/bar}baz");
assertEquals(3, l.getPartialPaths().size());
assertEquals("foo", l.getPartialPaths().get(0).value);
assertEquals(HierarchicalUriComponents.Type.PATH, l.getPartialPaths().get(0).type);
assertEquals("{/bar}", l.getPartialPaths().get(1).value);
assertEquals(HierarchicalUriComponents.Type.PATH_SEGMENT, l.getPartialPaths().get(1).type);
assertEquals("baz", l.getPartialPaths().get(2).value);
assertEquals(HierarchicalUriComponents.Type.PATH, l.getPartialPaths().get(2).type);
}
}

View File

@@ -63,49 +63,6 @@ public class UriTemplateTests {
assertEquals("Invalid expanded template", new URI("http://example.com/hotels/1/bookings/42"), result);
}
//SPR-12750
@Test
public void expandSlashPrefixedVariable() throws Exception {
Map<String, String> uriVariables = new HashMap<String, String>(2);
uriVariables.put("hotel", "1");
uriVariables.put("publicpath", "pics/logo.png");
uriVariables.put("scale", "150x150");
UriTemplate template = new UriTemplate(
"http://example.com/hotels/{hotel}/pic/{/publicpath}/size/{scale}");
URI result = template.expand(uriVariables);
assertEquals("Invalid expanded template",
new URI("http://example.com/hotels/1/pic/pics%2Flogo.png/size/150x150"),
result);
}
@Test
public void expandSlashPrefixedVariableInBetween() throws Exception {
Map<String, String> uriVariables = new HashMap<String, String>(2);
uriVariables.put("var1", "foo/bar");
uriVariables.put("var2", "baz");
UriTemplate template = new UriTemplate(
"http://example.com/part1/before-{/var1}-after/{var2}");
URI result = template.expand(uriVariables);
assertEquals("Invalid expanded template",
new URI("http://example.com/part1/before-foo%2Fbar-after/baz"),
result);
}
@Test
public void expandSlashPrefixedVariableAfterNonPrefixedVariable() throws Exception {
Map<String, String> uriVariables = new HashMap<String, String>(2);
uriVariables.put("var1", "foo/bar");
uriVariables.put("var2", "baz");
uriVariables.put("var3", "qux");
UriTemplate template = new UriTemplate(
"http://example.com/part1/before-{/var1}-{var2}-after/{var3}");
URI result = template.expand(uriVariables);
assertEquals("Invalid expanded template",
new URI("http://example.com/part1/before-foo%2Fbar-baz-after/qux"),
result);
}
@Test
public void expandMapDuplicateVariables() throws Exception {
UriTemplate template = new UriTemplate("/order/{c}/{c}/{c}");