summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-14 19:13:20 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2019-10-31 13:22:33 +0900
commitdcb35811cf240f771a0587ee20ec54b10594ff52 (patch)
tree5733d0a98aafe6c1aa4f7bdcf2a46a8d1769cd8a /ext
parentfd3873c0a32b4127e3178bf65bf5b114d3ab8de3 (diff)
downloadjson-dcb35811cf240f771a0587ee20ec54b10594ff52.tar.gz
[flori/json] Fixed unexpected illegal/malformed utf-8 error
flori/json@c34d01ff6a18dac04a90b2e0f820cdb1d5c7e1b2 does not consider US-ASCII compatible but non-UTF-8 encodings, and causes an error in RDoc tests. https://github.com/flori/json/commit/4f471bf590
Diffstat (limited to 'ext')
-rw-r--r--ext/json/ext/generator/generator.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c
index d14e471..f481346 100644
--- a/ext/json/ext/generator/generator.c
+++ b/ext/json/ext/generator/generator.c
@@ -846,11 +846,20 @@ static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
fbuffer_append_char(buffer, ']');
}
+#ifdef HAVE_RUBY_ENCODING_H
+static int enc_utf8_compatible_p(rb_encoding *enc)
+{
+ if (enc == rb_usascii_encoding()) return 1;
+ if (enc == rb_utf8_encoding()) return 1;
+ return 0;
+}
+#endif
+
static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
{
fbuffer_append_char(buffer, '"');
#ifdef HAVE_RUBY_ENCODING_H
- if (!rb_enc_str_asciicompat_p(obj)) {
+ if (!enc_utf8_compatible_p(rb_enc_get(obj))) {
obj = rb_str_encode(obj, CEncoding_UTF_8, 0, Qnil);
}
#endif