From 649c2796879aace90e2ec73a2a3728667af27d52 Mon Sep 17 00:00:00 2001 From: cola119 Date: Wed, 27 Jul 2022 00:27:55 +0900 Subject: [PATCH 1/2] src: fix to use replacement character --- src/node_i18n.cc | 6 +++++- test/parallel/test-whatwg-encoding-custom-textdecoder.js | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/node_i18n.cc b/src/node_i18n.cc index c537a247f55ff0..d96efaa9df7b2f 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -425,7 +425,11 @@ void ConverterObject::Create(const FunctionCallbackInfo& args) { nullptr, nullptr, nullptr, &status); } - new ConverterObject(env, obj, conv, flags); + auto converter = new ConverterObject(env, obj, conv, flags); + size_t sublen = ucnv_getMinCharSize(conv); + std::string sub(sublen, '?'); + converter->set_subst_chars(sub.c_str()); + args.GetReturnValue().Set(obj); } diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder.js b/test/parallel/test-whatwg-encoding-custom-textdecoder.js index 1fa65164c70678..a3a0cb58f15b86 100644 --- a/test/parallel/test-whatwg-encoding-custom-textdecoder.js +++ b/test/parallel/test-whatwg-encoding-custom-textdecoder.js @@ -199,3 +199,10 @@ if (common.hasIntl) { const str = decoder.decode(chunk); assert.strictEqual(str, 'foo\ufffd'); } + +{ + const decoder = new TextDecoder('Shift_JIS'); + const chunk = new Uint8Array([-1]); + const str = decoder.decode(chunk); + assert.strictEqual(str, '\ufffd'); +} From 30be3cd21cd01c1f95b5d8827ecec10f45d70efa Mon Sep 17 00:00:00 2001 From: cola119 Date: Wed, 27 Jul 2022 22:59:54 +0900 Subject: [PATCH 2/2] fixup! src: fix to use replacement character --- test/parallel/test-whatwg-encoding-custom-textdecoder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder.js b/test/parallel/test-whatwg-encoding-custom-textdecoder.js index a3a0cb58f15b86..fe08edc597d3f4 100644 --- a/test/parallel/test-whatwg-encoding-custom-textdecoder.js +++ b/test/parallel/test-whatwg-encoding-custom-textdecoder.js @@ -200,7 +200,7 @@ if (common.hasIntl) { assert.strictEqual(str, 'foo\ufffd'); } -{ +if (common.hasIntl) { const decoder = new TextDecoder('Shift_JIS'); const chunk = new Uint8Array([-1]); const str = decoder.decode(chunk);