UriTemplate properly quotes variable values (SPR-6854)
This commit is contained in:
parent
36940c5fc8
commit
54acebd086
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 Arjen Poutsma
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @see <a href="http://bitworking.org/projects/URI-Templates/">URI Templates</a>
|
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
|
* @see <a href="http://bitworking.org/projects/URI-Templates/">URI Templates</a>
|
||||||
*/
|
*/
|
||||||
public class UriTemplate {
|
public class UriTemplate {
|
||||||
|
|
||||||
|
|
@ -126,7 +126,7 @@ public class UriTemplate {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String uriVariable = uriVariableValues[i++].toString();
|
String uriVariable = uriVariableValues[i++].toString();
|
||||||
matcher.appendReplacement(buffer, uriVariable);
|
matcher.appendReplacement(buffer, Matcher.quoteReplacement(uriVariable));
|
||||||
}
|
}
|
||||||
matcher.appendTail(buffer);
|
matcher.appendTail(buffer);
|
||||||
return encodeUri(buffer.toString());
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 static org.junit.Assert.*;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/** @author Arjen Poutsma */
|
/**
|
||||||
|
* @author Arjen Poutsma
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
*/
|
||||||
public class UriTemplateTests {
|
public class UriTemplateTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -141,4 +144,12 @@ public class UriTemplateTests {
|
||||||
template = new UriTemplate("/search?query={query}#{fragment}");
|
template = new UriTemplate("/search?query={query}#{fragment}");
|
||||||
assertTrue(template.matches("/search?query=foo#bar"));
|
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…
Reference in New Issue