File tree Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -554,7 +554,8 @@ def eval_input
554
554
555
555
def handle_exception ( exc )
556
556
if exc . backtrace && exc . backtrace [ 0 ] =~ /\/ irb(2)?(\/ .*|-.*|\. rb)?:/ && exc . class . to_s !~ /^IRB/ &&
557
- !( SyntaxError === exc )
557
+ !( SyntaxError === exc ) && !( EncodingError === exc )
558
+ # The backtrace of invalid encoding hash (ex. {"\xAE": 1}) raises EncodingError without lineno.
558
559
irb_bug = true
559
560
else
560
561
irb_bug = false
Original file line number Diff line number Diff line change @@ -211,6 +211,8 @@ def check_code_block(code)
211
211
else
212
212
RubyVM ::InstructionSequence . compile ( code )
213
213
end
214
+ rescue EncodingError
215
+ # This is for a hash with invalid encoding symbol, {"\xAE": 1}
214
216
rescue SyntaxError => e
215
217
case e . message
216
218
when /unterminated (?:string|regexp) meets end of file/
Original file line number Diff line number Diff line change @@ -63,6 +63,13 @@ def test_evaluate_with_exception
63
63
assert_not_match ( /rescue _\. class/ , e . message )
64
64
end
65
65
66
+ def test_evaluate_with_encoding_error_without_lineno
67
+ assert_raise_with_message ( EncodingError , /invalid symbol/ ) {
68
+ @context . evaluate ( %q[{"\xAE": 1}] , 1 )
69
+ # The backtrace of this invalid encoding hash doesn't contain lineno.
70
+ }
71
+ end
72
+
66
73
def test_evaluate_with_onigmo_warning
67
74
assert_warning ( "(irb):1: warning: character class has duplicated range: /[aa]/\n " ) do
68
75
@context . evaluate ( '/[aa]/' , 1 )
You can’t perform that action at this time.
0 commit comments