зеркало из https://github.com/github/ruby.git
[flori/json] Fixed unexpected illegal/malformed utf-8 error
flori/json@c34d01ff6a 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
This commit is contained in:
Родитель
d7fa7e2c86
Коммит
2003755a2c
|
@ -806,11 +806,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
|
||||
|
|
|
@ -374,4 +374,10 @@ EOT
|
|||
assert_equal '["foo"]', JSON.generate([s.new('foo')])
|
||||
end
|
||||
end
|
||||
|
||||
if defined?(Encoding)
|
||||
def test_nonutf8_encoding
|
||||
assert_equal("\"5\u{b0}\"", "5\xb0".force_encoding("iso-8859-1").to_json)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче