Add support and test for invalid encoding input to decoder-browser#15
Add support and test for invalid encoding input to decoder-browser#15danieledler wants to merge 5 commits intocalvinmetcalf:masterfrom
Conversation
|
ok so the issue is that IE is the only one that doesn't have StringDecoder so that's why we don't use iconv-lite in the browser because that would balloon the size of the bundle for just IE support the indexes can be required separately but I think I may have forgot to document that so I'd really prefer not to bring in iconv-lite to the main build, there is some good stuff in this pull though |
decoder-browser.js
Outdated
| if (!encoding) { | ||
| return defaultDecoder; | ||
| } | ||
| enconding = String(encoding).trim(); |
There was a problem hiding this comment.
do we just need to check if it's a buffer?
There was a problem hiding this comment.
At least the Uint8Array buffer in the new test is decoded properly in its toString method, but what can we do otherwise? Then we need to know the encoding of the encoding? 😆 The worst thing that could happen I guess is that we get something like "[object Buffer]" and TextDecoder throws because of invalid encoding label, but then we get the default decoder. Or do you think about something else?
I just saw that I made a typo in that very line though! 😳
String(encoding)to not throw onencoding.trim()when for example the encoding content is retrieved from reading a file forgetting to add utf8 encodingTextDecoderwhich can otherwise throw on providing bad contentdecoder-browser