SPR-7135 - org.springframework.http.MediaType#checkParameters fails to process a Content-Type like application/xml;charset="utf-8"

This commit is contained in:
Arjen Poutsma
2010-04-27 08:26:51 +00:00
parent 8ce4037af2
commit c2707150b1
2 changed files with 19 additions and 1 deletions

View File

@@ -264,7 +264,7 @@ public class MediaType implements Comparable<MediaType> {
String attribute = entry.getKey();
String value = entry.getValue();
checkParameters(attribute, value);
m.put(attribute, value);
m.put(attribute, unquote(value));
}
this.parameters = Collections.unmodifiableMap(m);
}
@@ -293,10 +293,12 @@ public class MediaType implements Comparable<MediaType> {
Assert.hasLength(value, "parameter value must not be empty");
checkToken(attribute);
if (PARAM_QUALITY_FACTOR.equals(attribute)) {
value = unquote(value);
double d = Double.parseDouble(value);
Assert.isTrue(d >= 0D && d <= 1D, "Invalid quality value \"" + value + "\": should be between 0.0 and 1.0");
}
else if (PARAM_CHARSET.equals(attribute)) {
value = unquote(value);
Charset.forName(value);
}
else if (!isQuotedString(value)) {
@@ -308,6 +310,13 @@ public class MediaType implements Comparable<MediaType> {
return s.length() > 1 && s.startsWith("\"") && s.endsWith("\"") ;
}
private String unquote(String s) {
if (s == null) {
return null;
}
return isQuotedString(s) ? s.substring(1, s.length() - 1) : s;
}
/** Return the primary type. */
public String getType() {
return this.type;