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
554554
555555 def handle_exception ( exc )
556556 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.
558559 irb_bug = true
559560 else
560561 irb_bug = false
Original file line number Diff line number Diff line change @@ -211,6 +211,8 @@ def check_code_block(code)
211211 else
212212 RubyVM ::InstructionSequence . compile ( code )
213213 end
214+ rescue EncodingError
215+ # This is for a hash with invalid encoding symbol, {"\xAE": 1}
214216 rescue SyntaxError => e
215217 case e . message
216218 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
6363 assert_not_match ( /rescue _\. class/ , e . message )
6464 end
6565
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+
6673 def test_evaluate_with_onigmo_warning
6774 assert_warning ( "(irb):1: warning: character class has duplicated range: /[aa]/\n " ) do
6875 @context . evaluate ( '/[aa]/' , 1 )
You can’t perform that action at this time.
0 commit comments