-
-
Notifications
You must be signed in to change notification settings - Fork 295
Open
Description
In Node.js, UTF-8 decoding is fine
The issue is that in browsers:
Bufferis polyfilled to http://npmjs.com/package/buffer, which is old and invalidstring_decoderis polyfilled to https://npmjs.com/package/string_decoder, which is also old and invalid
And iconv-lite just uses those everywhere without checking
Example:
import iconv from 'iconv-lite'
console.log(escape(iconv.decode(Buffer.of(0xf0, 0x90, 0x80), 'utf8'))) // should be %uFFFD
console.log(escape(iconv.decode(Buffer.of(0xf0, 0x80, 0x80), 'utf8'))) // should be %uFFFD%uFFFD%uFFFDCorrect:
$ node iconv-test.js
%uFFFD
%uFFFD%uFFFD%uFFFDBut when run in browsers or React Native, it outputs:
%uFFFD
%uFFFD
Metadata
Metadata
Assignees
Labels
No labels