diff options
author | Benoit Daloze <[email protected]> | 2024-10-30 21:39:01 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-11-01 13:04:24 +0900 |
commit | eb19156a288b585c58f3161a86d5b10f8f9704b6 (patch) | |
tree | efb073499a4ce54f660745ab6b7afb992b7ece3a /test | |
parent | ebfa178b72e608d160aa21b4fc0864578de76f2b (diff) |
[ruby/json] Add test for parsing broken strings
https://github.com/ruby/json/commit/850bd077c4
Diffstat (limited to 'test')
-rw-r--r-- | test/json/json_parser_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/json/json_parser_test.rb b/test/json/json_parser_test.rb index 59cfcfa6e7..2e09ff7bfd 100644 --- a/test/json/json_parser_test.rb +++ b/test/json/json_parser_test.rb @@ -196,6 +196,22 @@ class JSONParserTest < Test::Unit::TestCase ) end + def test_parse_broken_string + # https://github.com/ruby/json/issues/138 + s = parse(%{["\x80"]})[0] + assert_equal("\x80", s) + assert_equal Encoding::UTF_8, s.encoding + assert_equal false, s.valid_encoding? + + s = parse(%{["\x80"]}.b)[0] + assert_equal("\x80", s) + assert_equal Encoding::UTF_8, s.encoding + assert_equal false, s.valid_encoding? + + input = %{["\x80"]}.dup.force_encoding(Encoding::US_ASCII) + assert_raise(Encoding::InvalidByteSequenceError) { parse(input) } + end + def test_parse_big_integers json1 = JSON(orig = (1 << 31) - 1) assert_equal orig, parse(json1) |