src: fix to use replacement character

PR-URL: https://github.com/nodejs/node/pull/43999
Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
Kohei Ueno 2022-07-29 14:47:56 +09:00 committed by GitHub
parent 28a9042ee6
commit e5add6659d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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);
}

View File

@ -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');
}