Skip to content

Commit

Permalink
src: fix to use replacement character
Browse files Browse the repository at this point in the history
PR-URL: #43999
Fixes: #43962
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
  • Loading branch information
cola119 authored and targos committed Sep 5, 2022
1 parent 8867e7c commit 5a5581f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/node_i18n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,11 @@ void ConverterObject::Create(const FunctionCallbackInfo<Value>& 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);
}

Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-whatwg-encoding-custom-textdecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,10 @@ if (common.hasIntl) {
const str = decoder.decode(chunk);
assert.strictEqual(str, 'foo\ufffd');
}

if (common.hasIntl) {
const decoder = new TextDecoder('Shift_JIS');
const chunk = new Uint8Array([-1]);
const str = decoder.decode(chunk);
assert.strictEqual(str, '\ufffd');
}

0 comments on commit 5a5581f

Please sign in to comment.