UriTemplate properly quotes variable values (SPR-6854)

master
Juergen Hoeller 15 years ago
parent 36940c5fc8
commit 54acebd086
  1. 6
      org.springframework.web/src/main/java/org/springframework/web/util/UriTemplate.java
  2. 17
      org.springframework.web/src/test/java/org/springframework/web/util/UriTemplateTests.java

@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 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.
@ -36,8 +36,8 @@ import org.springframework.util.Assert;
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @see <a href="http://bitworking.org/projects/URI-Templates/">URI Templates</a>
* @since 3.0
* @see <a href="http://bitworking.org/projects/URI-Templates/">URI Templates</a>
*/
public class UriTemplate {
@ -126,7 +126,7 @@ public class UriTemplate {
int i = 0;
while (matcher.find()) {
String uriVariable = uriVariableValues[i++].toString();
matcher.appendReplacement(buffer, uriVariable);
matcher.appendReplacement(buffer, Matcher.quoteReplacement(uriVariable));
}
matcher.appendTail(buffer);
return encodeUri(buffer.toString());

@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 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.
@ -26,7 +26,10 @@ import java.util.Map;
import static org.junit.Assert.*;
import org.junit.Test;
/** @author Arjen Poutsma */
/**
* @author Arjen Poutsma
* @author Juergen Hoeller
*/
public class UriTemplateTests {
@Test
@ -141,4 +144,12 @@ public class UriTemplateTests {
template = new UriTemplate("/search?query={query}#{fragment}");
assertTrue(template.matches("/search?query=foo#bar"));
}
}
@Test
public void expandWithDollar() {
UriTemplate template = new UriTemplate("/{a}");
URI uri = template.expand("$replacement");
assertEquals("/$replacement", uri.toString());
}
}

Loading…
Cancel
Save