Skip to content

Commit 54acebd

Browse files
committed
UriTemplate properly quotes variable values (SPR-6854)
1 parent 36940c5 commit 54acebd

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

org.springframework.web/src/main/java/org/springframework/web/util/UriTemplate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,8 +36,8 @@
3636
*
3737
* @author Arjen Poutsma
3838
* @author Juergen Hoeller
39-
* @see <a href="http://bitworking.org/projects/URI-Templates/">URI Templates</a>
4039
* @since 3.0
40+
* @see <a href="http://bitworking.org/projects/URI-Templates/">URI Templates</a>
4141
*/
4242
public class UriTemplate {
4343

@@ -126,7 +126,7 @@ public URI expand(Object... uriVariableValues) {
126126
int i = 0;
127127
while (matcher.find()) {
128128
String uriVariable = uriVariableValues[i++].toString();
129-
matcher.appendReplacement(buffer, uriVariable);
129+
matcher.appendReplacement(buffer, Matcher.quoteReplacement(uriVariable));
130130
}
131131
matcher.appendTail(buffer);
132132
return encodeUri(buffer.toString());

org.springframework.web/src/test/java/org/springframework/web/util/UriTemplateTests.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,10 @@
2626
import static org.junit.Assert.*;
2727
import org.junit.Test;
2828

29-
/** @author Arjen Poutsma */
29+
/**
30+
* @author Arjen Poutsma
31+
* @author Juergen Hoeller
32+
*/
3033
public class UriTemplateTests {
3134

3235
@Test
@@ -141,4 +144,12 @@ public void fragments() throws Exception {
141144
template = new UriTemplate("/search?query={query}#{fragment}");
142145
assertTrue(template.matches("/search?query=foo#bar"));
143146
}
144-
}
147+
148+
@Test
149+
public void expandWithDollar() {
150+
UriTemplate template = new UriTemplate("/{a}");
151+
URI uri = template.expand("$replacement");
152+
assertEquals("/$replacement", uri.toString());
153+
}
154+
155+
}

0 commit comments

Comments
 (0)