Browse Source

media types in HTTP Accept headers can be parsed with single quotes (-> Android 2.x)

Issue: SPR-9734
pull/1536/head
Juergen Hoeller 12 years ago
parent
commit
8b09b52720
  1. 7
      org.springframework.web/src/main/java/org/springframework/http/MediaType.java
  2. 8
      org.springframework.web/src/test/java/org/springframework/http/MediaTypeTests.java

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

@ -376,7 +376,12 @@ public class MediaType implements Comparable<MediaType> { @@ -376,7 +376,12 @@ public class MediaType implements Comparable<MediaType> {
}
private boolean isQuotedString(String s) {
return s.length() > 1 && s.startsWith("\"") && s.endsWith("\"") ;
if (s.length() < 2) {
return false;
}
else {
return ((s.startsWith("\"") && s.endsWith("\"")) || (s.startsWith("'") && s.endsWith("'")));
}
}
private String unquote(String s) {

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

@ -181,6 +181,14 @@ public class MediaTypeTests { @@ -181,6 +181,14 @@ public class MediaTypeTests {
assertEquals("\"v>alue\"", mediaType.getParameter("attr"));
}
// SPR-8917
@Test
public void parseMediaTypeSingleQuotedParameterValue() {
MediaType mediaType = MediaType.parseMediaType("audio/*;attr='v>alue'");
assertEquals("'v>alue'", mediaType.getParameter("attr"));
}
@Test(expected = IllegalArgumentException.class)
public void parseMediaTypeIllegalQuotedParameterValue() {
MediaType.parseMediaType("audio/*;attr=\"");

Loading…
Cancel
Save