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 1e280a993e8..612b09d89bb 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
@@ -33,9 +33,9 @@ import org.springframework.util.Assert;
* ({, }), which can be expanded to produce a URI.
*
http://example.com/hotels/1/bookings/42
- *
* @param uriVariables the map of uri variables
* @return the expanded uri
* @throws IllegalArgumentException if uriVariables is null; or if it does not contain
@@ -116,7 +113,6 @@ public final class UriTemplate {
* System.out.println(template.expand("1", "42));
*
* will print: http://example.com/hotels/1/bookings/42
- *
* @param uriVariableValues the array of uri variables
* @return the expanded uri
* @throws IllegalArgumentException if uriVariables is null; or if it does not contain
@@ -137,12 +133,11 @@ public final class UriTemplate {
m.appendReplacement(buffer, uriVariable);
}
m.appendTail(buffer);
- return URI.create(buffer.toString());
+ return encodeUri(buffer.toString());
}
/**
* Indicates whether the given URI matches this template.
- *
* @param uri the URI to match to
* @return true if it matches; false otherwise
*/
@@ -164,7 +159,6 @@ public final class UriTemplate {
* System.out.println(template.match("http://example.com/hotels/1/bookings/42"));
*
* will print: {hotel=1, booking=42}
- *
* @param uri the URI to match to
* @return a map of variable values
*/
@@ -182,6 +176,26 @@ public final class UriTemplate {
return result;
}
+ private static URI encodeUri(String uri) {
+ try {
+ int idx = uri.indexOf(':');
+ URI result;
+ if (idx != -1) {
+ String scheme = uri.substring(0, idx);
+ String ssp = uri.substring(idx + 1);
+ result = new URI(scheme, ssp, null);
+ }
+ else {
+ result = new URI(null, null, uri, null);
+ }
+ return result;
+ }
+ catch (URISyntaxException e) {
+ throw new IllegalArgumentException("Could not create URI from [" + uri + "]");
+ }
+ }
+
+
@Override
public String toString() {
return uriTemplate;
@@ -218,17 +232,11 @@ public final class UriTemplate {
if (start == end) {
return "";
}
- String result = fullPath.substring(start, end);
- try {
- URI uri = new URI(null, null, result, null);
- result = uri.toASCIIString();
- }
- catch (URISyntaxException e) {
- throw new IllegalArgumentException("Could not create URI from [" + fullPath + "]");
- }
+ String result = encodeUri(fullPath.substring(start, end)).toASCIIString();
return Pattern.quote(result);
}
+
private List