Skip to content

About implicit encoding and late errors #6

@sffc

Description

@sffc

The encoding of the byte payload is of increased impact for { type: "text" } than it is for other import types.

Evidence: If a JSON file contains invalid UTF-8, the HTML module loader throws an exception. Side note: HTML would ideally read the encoding from the Content-Type header, but it doesn't seem to do this.

HTML Demo: https://gist.github.com/sffc/6d62c6f0518485347bda688c4a2f20a4

I also tested this with Node.js, which also throws an exception.

$ nvm run 25 node.mjs
Running node v25.2.1 (npm v11.6.2)
<anonymous_script>:1
{

SyntaxError: /Users/sffc/mac_projects/sandbox/simplerserver/utf16le.json: Expected property name or '}' in JSON at position 1 (line 1 column 2)

The error is triggered virtually 100% of the time with utf16le. Triggering it with well-formed latin1 is possible but requires a specific byte sequence.

With this proposal, { type: "text" }, there won't be an opportunity to throw a SyntaxError, which causes implicitly garbled text to enter the scope of a JavaScript program, which is unfortunate to introduce in a new language feature.

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