Skip to content

[BUG] Content-Type charset parameters are parsed incorrectly #3652

Open

Description

@hutiefang76

Issue Description

Type: bug report

Describe what happened

SimpleHttpResponse.getBodyAsString() splits Content-Type on spaces rather than media-type parameters. A non-default response charset is ignored for text/plain;charset=ISO-8859-1, while quoted values or trailing parameters can cause charset lookup to fail. This corrupts non-ASCII heartbeat-response text or prevents it from being decoded.

Describe what you expected to happen

Honor a charset parameter regardless of whitespace after the semicolon, balanced double quotes, parameter-name case or later parameters. An absent charset should use the configured default; an unsupported charset should still fail explicitly.

How to reproduce it (as minimally and precisely as possible)

Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "text/plain;charset=ISO-8859-1");
byte[] body = "café".getBytes(Charset.forName("ISO-8859-1"));
SimpleHttpResponse response = new SimpleHttpResponse("HTTP/1.1 200 OK", headers, body);
assertEquals("café", response.getBodyAsString());

With the default UTF-8 configuration, this assertion fails on the current branch. Also try text/plain; charset="ISO-8859-1" and text/plain; charset=ISO-8859-1; boundary=xyz.

Tell us your environment

Sentinel 1.8 branch at a3f40ba; macOS ARM64; Java 17.0.18. The regression suite also passes on Java 1.8.0_492 with the patch.

Anything else we need to know?

The closed, unmerged PR #1590 addresses null checking, rather than parameter parsing. The current issue is scoped to charset parameter decoding. I can submit a fix with deterministic tests.

AI assistance: DeepSeek and Codex assisted reproduction, implementation and this description.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions