Skip to content

Reject non-ASCII characters in Display Strings, keep a leading U+FEFF - #90

Open
bardrop wants to merge 1 commit into
evert:mainfrom
bardrop-oss:fix-display-string-non-ascii
Open

bardrop wants to merge 1 commit into
evert:mainfrom
bardrop-oss:fix-display-string-non-ascii

Conversation

@bardrop

@bardrop bardrop commented Nov 20, 2026

Copy link
Copy Markdown

parseDisplayString checks each character with <= 0x1f or 0x7f..0xff, so anything above U+00FF passes. It is then pushed into a Uint8Array, which keeps only the low byte:

parseItem('%"Ł"')[0].toString();   // 'A'   (U+0141 -> 0x41)
parseItem('%"aŁb"')[0].toString(); // 'aAb'
parseItem('%"Ā"')[0].toString();   // '\u0000'

RFC 9651 section 4.2.10 says to fail if a character is not in VCHAR or SP, so these should throw, like "Ł" already does for plain strings. The check is now <= 0x1f || >= 0x7f.

Second, smaller thing in the same function: TextDecoder drops a leading BOM by default, so a value that starts with U+FEFF loses it on parse and does not round-trip:

parseItem('%"%ef%bb%bfa"')[0].toString();                 // 'a'
parseItem(serializeItem(new DisplayString('a')))[0]; // 'a'

Added ignoreBOM: true so the character is kept.

Tests are in a new test/parser-tests.js; all 3 fail on main and pass with the change. I also ran 100k random field values through the old and new parser: the only results that changed are values starting with %ef%bb%bf.

Note: make unit-test has 4 failures on main too, from round-tie-to-even cases that were added to serialisation-tests/number.json in the httpwg suite after the last CI run. They are not touched here.

Characters above U+00FF passed the range check and were cut to their
low byte when pushed into the Uint8Array, so %"Ł" parsed as "A" and
%"Ā" as a NUL. RFC 9651 section 4.2.10 says to fail on anything that
is not VCHAR or SP.

TextDecoder also drops a leading BOM by default, so a value starting
with U+FEFF lost that character on parse and did not round-trip.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant