Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress 'Maybe IRB bug!' message in extract_ruby_args #959

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/irb/command/internal_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module IRB
module Command
# Internal use only, for default command's backward compatibility.
module RubyArgsExtractor # :nodoc:
class Error < StandardError; end

def unwrap_string_literal(str)
return if str.empty?

Expand All @@ -16,10 +18,15 @@ def unwrap_string_literal(str)
end

def ruby_args(arg)
if arg =~ /\A([<=>]|([-+*\/%^&|!]|\*\*|\|\||&&)=)/
raise Error, "Invalid IRB::Command argument: #{arg.inspect}"
end
# Use throw and catch to handle arg that includes `;`
# For example: "1, kw: (2; 3); 4" will be parsed to [[1], { kw: 3 }]
catch(:EXTRACT_RUBY_ARGS) do
@irb_context.workspace.binding.eval "IRB::Command.extract_ruby_args #{arg}"
rescue
raise Error
end || [[], {}]
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/irb/test_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,18 @@ def test_measure_with_proc_warning
assert_match(/\A=> 3\n=> nil\n=> 3\n/, out)
assert_empty(c.class_variables)
end

def test_error_call
out, err = execute_lines("measure raise 'foo'+'bar'+'error'\n")
assert_empty err
assert_include(out, 'foobarerror')
assert_not_include(out, 'Maybe IRB bug')

out, err = execute_lines("measure = 1\n")
assert_empty err
assert_include(out, 'Invalid IRB::Command argument: "= 1"')
assert_not_include(out, 'Maybe IRB bug')
end
end

class IrbSourceTest < CommandTestCase
Expand Down
Loading