mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Suppress crashing when EncodingError has occurred without lineno
https://github.com/ruby/irb/commit/13572d8cdc
This commit is contained in:
parent
ffbb162f1a
commit
22477128cd
3 changed files with 11 additions and 1 deletions
|
@ -554,7 +554,8 @@ module IRB
|
|||
|
||||
def handle_exception(exc)
|
||||
if exc.backtrace && exc.backtrace[0] =~ /\/irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
|
||||
!(SyntaxError === exc)
|
||||
!(SyntaxError === exc) && !(EncodingError === exc)
|
||||
# The backtrace of invalid encoding hash (ex. {"\xAE": 1}) raises EncodingError without lineno.
|
||||
irb_bug = true
|
||||
else
|
||||
irb_bug = false
|
||||
|
|
|
@ -211,6 +211,8 @@ class RubyLex
|
|||
else
|
||||
RubyVM::InstructionSequence.compile(code)
|
||||
end
|
||||
rescue EncodingError
|
||||
# This is for a hash with invalid encoding symbol, {"\xAE": 1}
|
||||
rescue SyntaxError => e
|
||||
case e.message
|
||||
when /unterminated (?:string|regexp) meets end of file/
|
||||
|
|
|
@ -63,6 +63,13 @@ module TestIRB
|
|||
assert_not_match(/rescue _\.class/, e.message)
|
||||
end
|
||||
|
||||
def test_evaluate_with_encoding_error_without_lineno
|
||||
assert_raise_with_message(EncodingError, /invalid symbol/) {
|
||||
@context.evaluate(%q[{"\xAE": 1}], 1)
|
||||
# The backtrace of this invalid encoding hash doesn't contain lineno.
|
||||
}
|
||||
end
|
||||
|
||||
def test_evaluate_with_onigmo_warning
|
||||
assert_warning("(irb):1: warning: character class has duplicated range: /[aa]/\n") do
|
||||
@context.evaluate('/[aa]/', 1)
|
||||
|
|
Loading…
Add table
Reference in a new issue