Fixed wrong encoding of URI templates with @-signs (SPR-6874)

This commit is contained in:
Arjen Poutsma
2010-03-02 11:30:36 +00:00
parent e653a9cd03
commit d207c2294d
5 changed files with 17 additions and 7 deletions

View File

@@ -182,7 +182,7 @@ public class UriTemplate {
throw new IllegalStateException(ex);
}
catch (URISyntaxException ex) {
throw new IllegalArgumentException("Could not create URI from [" + uri + "]: " + ex);
throw new IllegalArgumentException("Could not create URI from [" + uri + "]: " + ex, ex);
}
}
@@ -201,24 +201,23 @@ public class UriTemplate {
Matcher m = NAMES_PATTERN.matcher(uriTemplate);
int end = 0;
while (m.find()) {
this.patternBuilder.append(encodeAndQuote(uriTemplate, end, m.start()));
this.patternBuilder.append(quote(uriTemplate, end, m.start()));
this.patternBuilder.append(VALUE_REGEX);
this.variableNames.add(m.group(1));
end = m.end();
}
this.patternBuilder.append(encodeAndQuote(uriTemplate, end, uriTemplate.length()));
this.patternBuilder.append(quote(uriTemplate, end, uriTemplate.length()));
int lastIdx = this.patternBuilder.length() - 1;
if (lastIdx >= 0 && this.patternBuilder.charAt(lastIdx) == '/') {
this.patternBuilder.deleteCharAt(lastIdx);
}
}
private String encodeAndQuote(String fullPath, int start, int end) {
private String quote(String fullPath, int start, int end) {
if (start == end) {
return "";
}
String result = encodeUri(fullPath.substring(start, end)).toASCIIString();
return Pattern.quote(result);
return Pattern.quote(fullPath.substring(start, end));
}
private List<String> getVariableNames() {

View File

@@ -61,7 +61,7 @@ public abstract class UriUtils {
private static final String SCHEME_PATTERN = "([^:/?#]+):";
private static final String USERINFO_PATTERN = "([^@]*)";
private static final String USERINFO_PATTERN = "([^@/]*)";
private static final String HOST_PATTERN = "([^/?#:]*)";