SPR-7869 - Accept-Charset header with '*' results in java.nio.charset.IllegalCharsetNameException
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3897 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
f49c52cda0
commit
746167be6f
|
|
@ -177,11 +177,15 @@ public class HttpHeaders implements MultiValueMap<String, String> {
|
||||||
String[] tokens = value.split(",\\s*");
|
String[] tokens = value.split(",\\s*");
|
||||||
for (String token : tokens) {
|
for (String token : tokens) {
|
||||||
int paramIdx = token.indexOf(';');
|
int paramIdx = token.indexOf(';');
|
||||||
|
String charsetName;
|
||||||
if (paramIdx == -1) {
|
if (paramIdx == -1) {
|
||||||
result.add(Charset.forName(token));
|
charsetName = token;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result.add(Charset.forName(token.substring(0, paramIdx)));
|
charsetName = token.substring(0, paramIdx);
|
||||||
|
}
|
||||||
|
if (!charsetName.equals("*")) {
|
||||||
|
result.add(Charset.forName(charsetName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
|
@ -66,6 +67,13 @@ public class HttpHeadersTests {
|
||||||
assertEquals("Invalid Accept header", "utf-8, iso-8859-1", headers.getFirst("Accept-Charset"));
|
assertEquals("Invalid Accept header", "utf-8, iso-8859-1", headers.getFirst("Accept-Charset"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void acceptCharsetWildcard() {
|
||||||
|
headers.set("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
|
||||||
|
assertEquals("Invalid Accept header", Arrays.asList(Charset.forName("ISO-8859-1"), Charset.forName("UTF-8")),
|
||||||
|
headers.getAcceptCharset());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void allow() {
|
public void allow() {
|
||||||
EnumSet<HttpMethod> methods = EnumSet.of(HttpMethod.GET, HttpMethod.POST);
|
EnumSet<HttpMethod> methods = EnumSet.of(HttpMethod.GET, HttpMethod.POST);
|
||||||
|
|
@ -222,11 +230,12 @@ public class HttpHeadersTests {
|
||||||
@Test
|
@Test
|
||||||
public void contentDisposition() {
|
public void contentDisposition() {
|
||||||
headers.setContentDispositionFormData("name", null);
|
headers.setContentDispositionFormData("name", null);
|
||||||
assertEquals("Invalid Content-Disposition header", "form-data; name=\"name\"", headers.getFirst("Content-Disposition"));
|
assertEquals("Invalid Content-Disposition header", "form-data; name=\"name\"",
|
||||||
|
headers.getFirst("Content-Disposition"));
|
||||||
|
|
||||||
headers.setContentDispositionFormData("name", "filename");
|
headers.setContentDispositionFormData("name", "filename");
|
||||||
assertEquals("Invalid Content-Disposition header", "form-data; name=\"name\"; filename=\"filename\"", headers.getFirst("Content-Disposition"));
|
assertEquals("Invalid Content-Disposition header", "form-data; name=\"name\"; filename=\"filename\"",
|
||||||
|
headers.getFirst("Content-Disposition"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue