File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,22 @@ def test_parse_some_strings
196
196
)
197
197
end
198
198
199
+ def test_parse_broken_string
200
+ # https://github.com/ruby/json/issues/138
201
+ s = parse ( %{["\x80 "]} ) [ 0 ]
202
+ assert_equal ( "\x80 " , s )
203
+ assert_equal Encoding ::UTF_8 , s . encoding
204
+ assert_equal false , s . valid_encoding?
205
+
206
+ s = parse ( %{["\x80 "]} . b ) [ 0 ]
207
+ assert_equal ( "\x80 " , s )
208
+ assert_equal Encoding ::UTF_8 , s . encoding
209
+ assert_equal false , s . valid_encoding?
210
+
211
+ input = %{["\x80 "]} . dup . force_encoding ( Encoding ::US_ASCII )
212
+ assert_raise ( Encoding ::InvalidByteSequenceError ) { parse ( input ) }
213
+ end
214
+
199
215
def test_parse_big_integers
200
216
json1 = JSON ( orig = ( 1 << 31 ) - 1 )
201
217
assert_equal orig , parse ( json1 )
You can’t perform that action at this time.
0 commit comments