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:
parent
ab0dbfbe6d
commit
6cff2bfa46
2 changed files with 11 additions and 1 deletions
|
@ -533,7 +533,8 @@ class Pry
|
||||||
# valid_expression?("class Hello") #=> false
|
# valid_expression?("class Hello") #=> false
|
||||||
# valid_expression?("class Hello; end") #=> true
|
# valid_expression?("class Hello; end") #=> true
|
||||||
def valid_expression?(code)
|
def valid_expression?(code)
|
||||||
RubyParser.new.parse(code)
|
# NOTE: we're using .dup because RubyParser mutates the input
|
||||||
|
RubyParser.new.parse(code.dup)
|
||||||
true
|
true
|
||||||
rescue Racc::ParseError, SyntaxError
|
rescue Racc::ParseError, SyntaxError
|
||||||
false
|
false
|
||||||
|
|
|
@ -207,6 +207,15 @@ describe Pry do
|
||||||
end
|
end
|
||||||
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
|
describe "history arrays" do
|
||||||
it 'sets _ to the last result' do
|
it 'sets _ to the last result' do
|
||||||
res = []
|
res = []
|
||||||
|
|
Loading…
Reference in a new issue