提交 e8fc90ce 编写于 作者: R Rossen Stoyanchev

SPR-8917 Fix issue with quoted parameter values in MediaType.

上级 b0c735fe
...@@ -331,7 +331,7 @@ public class MediaType implements Comparable<MediaType> { ...@@ -331,7 +331,7 @@ public class MediaType implements Comparable<MediaType> {
String attribute = entry.getKey(); String attribute = entry.getKey();
String value = entry.getValue(); String value = entry.getValue();
checkParameters(attribute, value); checkParameters(attribute, value);
m.put(attribute, unquote(value)); m.put(attribute, value);
} }
this.parameters = Collections.unmodifiableMap(m); this.parameters = Collections.unmodifiableMap(m);
} }
...@@ -428,7 +428,7 @@ public class MediaType implements Comparable<MediaType> { ...@@ -428,7 +428,7 @@ public class MediaType implements Comparable<MediaType> {
*/ */
public Charset getCharSet() { public Charset getCharSet() {
String charSet = getParameter(PARAM_CHARSET); String charSet = getParameter(PARAM_CHARSET);
return (charSet != null ? Charset.forName(charSet) : null); return (charSet != null ? Charset.forName(unquote(charSet)) : null);
} }
/** /**
...@@ -438,7 +438,7 @@ public class MediaType implements Comparable<MediaType> { ...@@ -438,7 +438,7 @@ public class MediaType implements Comparable<MediaType> {
*/ */
public double getQualityValue() { public double getQualityValue() {
String qualityFactory = getParameter(PARAM_QUALITY_FACTOR); String qualityFactory = getParameter(PARAM_QUALITY_FACTOR);
return (qualityFactory != null ? Double.parseDouble(qualityFactory) : 1D); return (qualityFactory != null ? Double.parseDouble(unquote(qualityFactory)) : 1D);
} }
/** /**
......
...@@ -173,9 +173,12 @@ public class MediaTypeTests { ...@@ -173,9 +173,12 @@ public class MediaTypeTests {
MediaType.parseMediaType("text/html; charset=foo-bar"); MediaType.parseMediaType("text/html; charset=foo-bar");
} }
// SPR-8917
@Test @Test
public void parseMediaTypeQuotedParameterValue() { public void parseMediaTypeQuotedParameterValue() {
MediaType.parseMediaType("audio/*;attr=\"v>alue\""); MediaType mediaType = MediaType.parseMediaType("audio/*;attr=\"v>alue\"");
assertEquals("\"v>alue\"", mediaType.getParameter("attr"));
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册