Skip to content

Commit 2c6e3bc

Browse files
eregonhsbt
authored andcommitted
Raise the correct exception in fast_serialize_string
* Related to ruby/json#344
1 parent 1cf1bf9 commit 2c6e3bc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/json/json_generator_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,23 @@ def test_invalid_encoding_string
443443
"\x82\xAC\xEF".to_json
444444
end
445445
assert_includes error.message, "source sequence is illegal/malformed utf-8"
446+
447+
error = assert_raise(JSON::GeneratorError) do
448+
JSON.dump("\x82\xAC\xEF")
449+
end
450+
assert_includes error.message, "source sequence is illegal/malformed utf-8"
451+
452+
# These pass on the pure-Ruby generator but not with the native extension
453+
# https://github.com/ruby/json/issues/634
454+
if defined?(JSON::Pure)
455+
assert_raise(Encoding::UndefinedConversionError) do
456+
"\x82\xAC\xEF".b.to_json
457+
end
458+
459+
assert_raise(Encoding::UndefinedConversionError) do
460+
JSON.dump("\x82\xAC\xEF".b)
461+
end
462+
end
446463
end
447464

448465
if defined?(JSON::Ext::Generator) and RUBY_PLATFORM != "java"

0 commit comments

Comments
 (0)