Skip to content

Commit

Permalink
src: fix to use replacement character
Browse files Browse the repository at this point in the history
  • Loading branch information
cola119 committed Jul 26, 2022
1 parent 8f0dee1 commit 649c279
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
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
Expand Up @@ -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');
}

0 comments on commit 649c279

Please sign in to comment.