summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2024-10-21 21:26:03 +0200
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2024-10-26 18:44:15 +0900
commit2c6e3bc71e12e12ad6949502e2b161171ca56840 (patch)
treea921c11be6e305f2c9355e2c5549f75a2a9877ac /test
parent1cf1bf9588261263fbf5d423d4786d59bc2600f7 (diff)
Raise the correct exception in fast_serialize_string
* Related to https://github.com/ruby/json/issues/344
Diffstat (limited to 'test')
-rwxr-xr-xtest/json/json_generator_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/json/json_generator_test.rb b/test/json/json_generator_test.rb
index 667baa03a9..6730898d4f 100755
--- a/test/json/json_generator_test.rb
+++ b/test/json/json_generator_test.rb
@@ -443,6 +443,23 @@ EOT
"\x82\xAC\xEF".to_json
end
assert_includes error.message, "source sequence is illegal/malformed utf-8"
+
+ error = assert_raise(JSON::GeneratorError) do
+ JSON.dump("\x82\xAC\xEF")
+ end
+ assert_includes error.message, "source sequence is illegal/malformed utf-8"
+
+ # These pass on the pure-Ruby generator but not with the native extension
+ # https://github.com/ruby/json/issues/634
+ if defined?(JSON::Pure)
+ assert_raise(Encoding::UndefinedConversionError) do
+ "\x82\xAC\xEF".b.to_json
+ end
+
+ assert_raise(Encoding::UndefinedConversionError) do
+ JSON.dump("\x82\xAC\xEF".b)
+ end
+ end
end
if defined?(JSON::Ext::Generator) and RUBY_PLATFORM != "java"