Skip to content

Commit e8fc90c

Browse files
committed
SPR-8917 Fix issue with quoted parameter values in MediaType.
1 parent b0c735f commit e8fc90c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

org.springframework.web/src/main/java/org/springframework/http/MediaType.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public MediaType(String type, String subtype, Map<String, String> parameters) {
331331
String attribute = entry.getKey();
332332
String value = entry.getValue();
333333
checkParameters(attribute, value);
334-
m.put(attribute, unquote(value));
334+
m.put(attribute, value);
335335
}
336336
this.parameters = Collections.unmodifiableMap(m);
337337
}
@@ -428,7 +428,7 @@ public boolean isConcrete() {
428428
*/
429429
public Charset getCharSet() {
430430
String charSet = getParameter(PARAM_CHARSET);
431-
return (charSet != null ? Charset.forName(charSet) : null);
431+
return (charSet != null ? Charset.forName(unquote(charSet)) : null);
432432
}
433433

434434
/**
@@ -438,7 +438,7 @@ public Charset getCharSet() {
438438
*/
439439
public double getQualityValue() {
440440
String qualityFactory = getParameter(PARAM_QUALITY_FACTOR);
441-
return (qualityFactory != null ? Double.parseDouble(qualityFactory) : 1D);
441+
return (qualityFactory != null ? Double.parseDouble(unquote(qualityFactory)) : 1D);
442442
}
443443

444444
/**

org.springframework.web/src/test/java/org/springframework/http/MediaTypeTests.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,12 @@ public void parseMediaTypeIllegalCharset() {
173173
MediaType.parseMediaType("text/html; charset=foo-bar");
174174
}
175175

176+
// SPR-8917
177+
176178
@Test
177179
public void parseMediaTypeQuotedParameterValue() {
178-
MediaType.parseMediaType("audio/*;attr=\"v>alue\"");
180+
MediaType mediaType = MediaType.parseMediaType("audio/*;attr=\"v>alue\"");
181+
assertEquals("\"v>alue\"", mediaType.getParameter("attr"));
179182
}
180183

181184
@Test(expected = IllegalArgumentException.class)

0 commit comments

Comments
 (0)