You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The root cause seems to be the string encoder assuming that any character \ud800 is the first half of a well formed UTF-16 surrogate pair. That assumption fails in the following cases:
Code points U+E000 to U+FFFF
Unpaired surrogates
JavaScript strings are not necessarily well formed UTF-16. The code needs to process characters in the range \ud800 to \udbff by checking whether they are followed by a character in the range \udc00 to \udfff, and if not, encoding U+FFFD instead. Anything \udc00 to \udfff by itself should also be encoded as U+FFFD.
For example, CBOR.encode("\uff08\u9999\u6e2f\uff09") gives 6bf3928699e6b8aff3929080 rather than the expected 6cefbc88e9a699e6b8afefbc89.
The text was updated successfully, but these errors were encountered:
Typescript rewrite
Rewritten to TypeScript for Deno support and Node typescript definitions, now as a ponyfill.
Added tests for more scenarios and to bring coverage up.
Modernized syntax and tests.
Added code quality and coverage analysis.
Removed default polyfill behavior and added back as an optional module.
Addresses the following issues:
paroga#27
paroga#24
paroga#21
paroga#13
The root cause seems to be the string encoder assuming that any character
\ud800
is the first half of a well formed UTF-16 surrogate pair. That assumption fails in the following cases:JavaScript strings are not necessarily well formed UTF-16. The code needs to process characters in the range
\ud800
to\udbff
by checking whether they are followed by a character in the range\udc00
to\udfff
, and if not, encoding U+FFFD instead. Anything\udc00
to\udfff
by itself should also be encoded as U+FFFD.For example,
CBOR.encode("\uff08\u9999\u6e2f\uff09")
gives6bf3928699e6b8aff3929080
rather than the expected6cefbc88e9a699e6b8afefbc89
.The text was updated successfully, but these errors were encountered: