Quote a value for an error message, as JSON.stringify does, and also escape what it
leaves raw although a terminal acts on it or no one can see it: DEL, the C1 controls, every
Unicode format character (bidi overrides, zero-width characters, the soft hyphen), the line
and paragraph separators U+2028/U+2029 and lone surrogates (JSON.stringify writes those as
\ud800 already). A refused id or filter is echoed in messages; an override in it would
reorder the rest of the line ("Trojan Source"), and a zero-width space in it would make the
refusal look like one of a valid value. A value longer than MAX_QUOTED_LENGTH (200)
characters is cut, and the "…" goes after the closing quote ("AAAA"…), so it does not read
as part of the value. The quoted part stays a valid JSON string.
Quote a value for an error message, as
JSON.stringifydoes, and also escape what it leaves raw although a terminal acts on it or no one can see it: DEL, the C1 controls, every Unicode format character (bidi overrides, zero-width characters, the soft hyphen), the line and paragraph separators U+2028/U+2029 and lone surrogates (JSON.stringify writes those as\ud800already). A refused id or filter is echoed in messages; an override in it would reorder the rest of the line ("Trojan Source"), and a zero-width space in it would make the refusal look like one of a valid value. A value longer thanMAX_QUOTED_LENGTH(200) characters is cut, and the "…" goes after the closing quote ("AAAA"…), so it does not read as part of the value. The quoted part stays a valid JSON string.