Skip to content

Send the client-side JSON in UTF-8 #149

Open

Description

@jwrosewell

The client-side JSON endpoint (/51dpipeline/json) sends application/json written through the response's writer in the response's character encoding (ClientsidePropertyServiceCore.java line 281 at 30e48867). The servlet API makes that ISO-8859-1 when the application sets none, so a value with a character outside Latin-1, such as a city name, reaches the browser as bytes that are not UTF-8.

RFC 8259 section 8.1 says "JSON text exchanged between systems that are not part of a closed ecosystem MUST be encoded using UTF-8", and section 11 defines no charset parameter.

Write the JSON's UTF-8 bytes through the output stream with Content-Length counted in those bytes, and leave Content-Type as application/json, as the specification's table gives it. The JavaScript endpoint is written the same way, so decide its encoding in the same change, and whether its Content-Type should name the charset.

Test with a value outside Latin-1 and no encoding set by the application, red first.

Found in the review of 51degrees-java#67.

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