File tree 2 files changed +10
-0
lines changed
2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -450,6 +450,9 @@ module String
450
450
def to_json ( state = nil , *args )
451
451
state = State . from_state ( state )
452
452
if encoding == ::Encoding ::UTF_8
453
+ unless valid_encoding?
454
+ raise GeneratorError , "source sequence is illegal/malformed utf-8"
455
+ end
453
456
string = self
454
457
else
455
458
string = encode ( ::Encoding ::UTF_8 )
Original file line number Diff line number Diff line change @@ -438,6 +438,13 @@ def to_s; self; end
438
438
end
439
439
end
440
440
441
+ def test_invalid_encoding_string
442
+ error = assert_raise ( JSON ::GeneratorError ) do
443
+ "\x82 \xAC \xEF " . to_json
444
+ end
445
+ assert_includes error . message , "source sequence is illegal/malformed utf-8"
446
+ end
447
+
441
448
if defined? ( JSON ::Ext ::Generator ) and RUBY_PLATFORM != "java"
442
449
def test_string_ext_included_calls_super
443
450
included = false
You can’t perform that action at this time.
0 commit comments