Skip to content

Commit

Permalink
Use lowercase for charsets #11741
Browse files Browse the repository at this point in the history
Fix #11741 as per the WhatTFWG recommendations, use lower case for charset names.
Took the opportunity for some minor optimizations:
 + use the already made HttpField instance in MimeTypes.Type rather than create a new one in the HttpParser.CACHE
 + keep the MimeType.Type associated with the pre encoded Content-Type fields
  • Loading branch information
gregw committed Oct 6, 2024
1 parent 3d7f5da commit 6c0b6f9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
Expand Down Expand Up @@ -146,7 +147,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse response) throw

// Now test for properly formatted HTTP Response Headers.
assertThat("Response Code", response.getStatus(), is(200));
assertThat("Response Header Content-Type", response.get("Content-Type"), is("text/plain;charset=utf-8"));
assertThat("Response Header Content-Type", response.get("Content-Type"), equalToIgnoringCase("text/plain;charset=utf-8"));

String expected = StringUtil.replace(actualPathInfo, "%0A", " "); // replace OBS fold with space
expected = URLDecoder.decode(expected, StandardCharsets.UTF_8); // decode the rest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
Expand Down Expand Up @@ -147,7 +148,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse response) throw

// Now test for properly formatted HTTP Response Headers.
assertThat("Response Code", response.getStatus(), is(200));
assertThat("Response Header Content-Type", response.get("Content-Type"), is("text/plain;charset=utf-8"));
assertThat("Response Header Content-Type", response.get("Content-Type"), equalToIgnoringCase("text/plain;charset=utf-8"));

String expected = StringUtil.replace(actualPathInfo, "%0A", " "); // replace OBS fold with space
expected = URLDecoder.decode(expected, StandardCharsets.UTF_8); // decode the rest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -242,7 +243,7 @@ public void testMultilineResponseHeaderValue() throws Exception

// Now test for properly formatted HTTP Response Headers.
assertThat("Response Code", response.getStatus(), is(200));
assertThat("Response Header Content-Type", response.get("Content-Type"), is("text/plain;charset=UTF-8"));
assertThat("Response Header Content-Type", response.get("Content-Type"), equalToIgnoringCase("text/plain;charset=utf-8"));

String expected = StringUtil.replace(actualPathInfo, "%0a", " "); // replace OBS fold with space
expected = StringUtil.replace(expected, "%0A", " "); // replace OBS fold with space
Expand Down

0 comments on commit 6c0b6f9

Please sign in to comment.