Uh oh!
There was an error while loading. Please reload this page.
test: add tests for invalid UTF-8 - #40351
Conversation
0995716 to
18827d1CompareThere was a problem hiding this comment.
// Run with --expose-internals flagconstassert=require('assert');const{ toUSVString }=require('internal/util');constdecoder=newTextDecoder();constchunk=Buffer.from([0x66,0x6f,0x6f,0xed,0xa0,0x80]);// foo + U+D800conststr=decoder.decode(chunk);assert.strictEqual(toUSVString(str),'foo\ufffd');TextDecoder() already replaces each byte of the surrogate code point with U+FFFD.
Hmm both Chrome and Safari work like this PR: newBlob([newUint8Array([0x66,0x6f,0x6f,0xed,0xa0,0x80])]).text().then((str)=>str==='foo\ufffd\ufffd\ufffd').then(console.log);but this is not consistent with const{ toUSVString }=require('internal/util');toUSVString('foo\ud800');// returns 'foo\ufffd'; |
git-srinivas
commented
Oct 8, 2021
|
ronag
commented
Oct 8, 2021
Does your tests pass without the fix? |
git-srinivas
commented
Oct 11, 2021
yes. I ran test cases with |
ronag
commented
Oct 11, 2021
Then I don't think this needs fixing. I would propose you remove the changes but keep the tests. We should still merge the tests. |
git-srinivas
commented
Oct 12, 2021
@lpinca@ronag I tried with |
All surrogates are 3 bytes and in this range: byte 1 = ED
That's because |
18827d1 to
5fa492aCompareThere was a problem hiding this comment.
This does not make much sense because passthrough.write() and passthrough.end() will call Buffer.from() when the chunk is written. If anything, chunks should be Buffers or Uint8Arrays.
There was a problem hiding this comment.
Similar to the one above this does not make much sense to me. When decoder.decode(chunk) is called, chunk is already U+FFFD (valid UTF-8).
4fb8c8a to
e5857baCompareUh oh!
There was an error while loading. Please reload this page.
lpinca
commented
Oct 22, 2021
@git-srinivas if you can please
|
git-srinivas
commented
Oct 22, 2021
Sure @lpinca I'll do the changes |
22de91f to
50b943bComparelpinca
commented
Oct 22, 2021
@git-srinivas can I suggest something like this? I find the current commit message a bit misleading because Thank you. |
Verify that `Blob.prototype.text()`, `streamConsumers.text()` and `TextDecoder.prototype.decode()` work as expected with invalid UTF-8. Fixes: nodejs#39804
50b943b to
75c69afComparenodejs-github-bot
commented
Nov 11, 2021
nodejs-github-bot
commented
Nov 12, 2021
nodejs-github-bot
commented
Nov 13, 2021
nodejs-github-bot
commented
Nov 13, 2021
nodejs-github-bot
commented
Nov 13, 2021
nodejs-github-bot
commented
Nov 13, 2021
nodejs-github-bot
commented
Nov 14, 2021
nodejs-github-bot
commented
Nov 14, 2021
nodejs-github-bot
commented
Nov 15, 2021
Landed in dc35aef. |
Verify that `Blob.prototype.text()`, `streamConsumers.text()` and `TextDecoder.prototype.decode()` work as expected with invalid UTF-8. PR-URL: #40351 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
Verify that `Blob.prototype.text()`, `streamConsumers.text()` and `TextDecoder.prototype.decode()` work as expected with invalid UTF-8. PR-URL: #40351 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
Verify that `Blob.prototype.text()`, `streamConsumers.text()` and `TextDecoder.prototype.decode()` work as expected with invalid UTF-8. PR-URL: #40351 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
Verify that `Blob.prototype.text()`, `streamConsumers.text()` and `TextDecoder.prototype.decode()` work as expected with invalid UTF-8. PR-URL: #40351 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
Fixes: #39804