Re:How fast can you validate UTF-8 strings in JavaScript?
by wolverine876 on Saturday January 20, 2024 @03:47PM
(#39072135)
As on example, you could mislead users by replacing valid codepoints (characters) with visually identical ones, for example in URLs.
[ Parent
| on HN ]
Re:How fast can you validate UTF-8 strings in JavaScript?
by orangepanda on Saturday January 20, 2024 @03:52PM
(#39072186)
Wouldn’t "visually identical” tokens still be valid utf8?
Re:How fast can you validate UTF-8 strings in JavaScript?
by wolverine876 on Saturday January 20, 2024 @03:54PM
(#39072210)
It depends on the meaning of 'valid UTF-8'. They could be 'UTF-8 that is invalid for my application', but still be 'strings that are valid under the UTF-8 specification'.
Re:How fast can you validate UTF-8 strings in JavaScript?
by LoganDark on Saturday January 20, 2024 @03:58PM
(#39072250)
There is no such thing as "UTF-8 that is invalid for my application". Any properly encoded sequence of UTF-8 codepoints is valid UTF-8. Your application may have constraints on the codepoints that it should accept, but that does not suddenly make them improperly encoded. Using visually-similar lookalikes does not make a UTF-8 string invalid.
Re:How fast can you validate UTF-8 strings in JavaScript?
by wolverine876 on Saturday January 20, 2024 @04:06PM
(#39072322)
> There is no such thing as "UTF-8 that is invalid for my application".
In fact, yes there is! Your application may vary. :)
Re:How fast can you validate UTF-8 strings in JavaScript?
by LoganDark on Sunday January 21, 2024 @12:18AM
(#39075806)
UTF-8 doesn't vary, it's just an encoding.
Re:How fast can you validate UTF-8 strings in JavaScript?
by LoganDark on Saturday January 20, 2024 @03:52PM
(#39072190)
That's not what invalid UTF-8 means. It doesn't mean replacing codepoints with other codepoints, it means that the encoding of the codepoints is invalid. Since JavaScript uses UTF-16 strings, it's possible to create JavaScript strings that don't have a valid UTF-8 representation (I believe unpaired surrogates can do this). Also, if you are working with raw bytes, there is no guarantee that it has any encoding at all (this seems to be what the article is about). There is WTF-8 [0] that proposes a possible solution to the UTF-16 problem, but purely as an internal representation and not as an interchange format. I think the Rust standard library uses WTF-8 to represent Windows wide-strings, which allows ASCII and UTF-8 algorithms to work on them, while still being able to represent any UTF-16 string.