SPR-7135 - org.springframework.http.MediaType#checkParameters fails to process a Content-Type like application/xml;charset="utf-8"
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user