From 54acebd086306e7f7b875f09082c2b703857880b Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 17 Feb 2010 21:58:56 +0000 Subject: [PATCH] UriTemplate properly quotes variable values (SPR-6854) --- .../springframework/web/util/UriTemplate.java | 6 +++--- .../web/util/UriTemplateTests.java | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/org.springframework.web/src/main/java/org/springframework/web/util/UriTemplate.java b/org.springframework.web/src/main/java/org/springframework/web/util/UriTemplate.java index f005806a85a..b35ab47d00d 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/util/UriTemplate.java +++ b/org.springframework.web/src/main/java/org/springframework/web/util/UriTemplate.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 URI Templates * @since 3.0 + * @see URI Templates */ 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()); diff --git a/org.springframework.web/src/test/java/org/springframework/web/util/UriTemplateTests.java b/org.springframework.web/src/test/java/org/springframework/web/util/UriTemplateTests.java index cbef8ed337d..4dee7a75068 100644 --- a/org.springframework.web/src/test/java/org/springframework/web/util/UriTemplateTests.java +++ b/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. @@ -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")); } -} \ No newline at end of file + + @Test + public void expandWithDollar() { + UriTemplate template = new UriTemplate("/{a}"); + URI uri = template.expand("$replacement"); + assertEquals("/$replacement", uri.toString()); + } + +}