1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

.dup code before letting RubyParser mangle it

This commit is contained in:
Conrad Irwin 2011-10-11 23:19:37 -07:00
parent ab0dbfbe6d
commit 6cff2bfa46
2 changed files with 11 additions and 1 deletions

View file

@ -533,7 +533,8 @@ class Pry
# valid_expression?("class Hello") #=> false
# valid_expression?("class Hello; end") #=> true
def valid_expression?(code)
RubyParser.new.parse(code)
# NOTE: we're using .dup because RubyParser mutates the input
RubyParser.new.parse(code.dup)
true
rescue Racc::ParseError, SyntaxError
false

View file

@ -207,6 +207,15 @@ describe Pry do
end
end
describe "valid_expression?" do
it "should not mutate the input!" do
clean = "puts <<-FOO\nhi\nFOO\n"
a = clean.dup
Pry.new.valid_expression?(a)
a.should == clean
end
end
describe "history arrays" do
it 'sets _ to the last result' do
res = []