diff --git a/src/json.c b/src/json.c index 928825e034..9c03d09ca6 100644 --- a/src/json.c +++ b/src/json.c @@ -225,8 +225,25 @@ json_has_suffix (const char *string, const char *suffix) static Lisp_Object json_make_string (const char *data, ptrdiff_t size) { - return code_convert_string (make_specified_string (data, -1, size, false), - Qutf_8_unix, Qt, false, true, true); + char* ptr = (char*)data + size; + bool ascii_only = true; + + while (ptr > data) { + if (!ASCII_CHAR_P(*ptr)) + { + ascii_only = false; + break; + } + ptr--; + } + + if (ascii_only) + /* Wasn't sure if the last arg should better be true here, but + it doesn't seem to affect the behavior or correctness, so far. */ + return make_specified_string (data, -1, size, false); + else + return code_convert_string (make_specified_string (data, -1, size, false), + Qutf_8_unix, Qt, false, true, true); } /* Create a multibyte Lisp string from the NUL-terminated UTF-8