diff options
author | James M Snell <jasnell@gmail.com> | 2021-04-21 18:23:55 +0300 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2021-04-24 12:40:56 +0300 |
commit | 639fa3255bc553e97fd14b13f424a9fbf1b90d3d (patch) | |
tree | d579f09c57b379930689b85d2b4952ee03a56d57 /src/node_i18n.cc | |
parent | 720fdf2f80b4973b9f5276df6ebf4d67e17e37a2 (diff) |
src: fix setting Converter sub char length
Signed-off-by: James M Snell <jasnell@gmail.com>
Fixes: https://github.com/nodejs/node/issues/38330
PR-URL: https://github.com/nodejs/node/pull/38331
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'src/node_i18n.cc')
-rw-r--r-- | src/node_i18n.cc | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/node_i18n.cc b/src/node_i18n.cc index 48f95ceb68d..42e618ac301 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -148,8 +148,13 @@ MaybeLocal<Object> Transcode(Environment* env, *status = U_ZERO_ERROR; MaybeLocal<Object> ret; MaybeStackBuffer<char> result; - Converter to(toEncoding, "?"); + Converter to(toEncoding); Converter from(fromEncoding); + + size_t sublen = ucnv_getMinCharSize(to.conv()); + std::string sub(sublen, '?'); + to.set_subst_chars(sub.c_str()); + const uint32_t limit = source_length * to.max_char_size(); result.AllocateSufficientStorage(limit); char* target = *result; @@ -190,7 +195,12 @@ MaybeLocal<Object> TranscodeFromUcs2(Environment* env, *status = U_ZERO_ERROR; MaybeStackBuffer<UChar> sourcebuf; MaybeLocal<Object> ret; - Converter to(toEncoding, "?"); + Converter to(toEncoding); + + size_t sublen = ucnv_getMinCharSize(to.conv()); + std::string sub(sublen, '?'); + to.set_subst_chars(sub.c_str()); + const size_t length_in_chars = source_length / sizeof(UChar); CopySourceBuffer(&sourcebuf, source, source_length, length_in_chars); MaybeStackBuffer<char> destbuf(length_in_chars); |