Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions lib/method_source/code_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def complete_expression?(str)
eval("BEGIN{throw :valid}\n#{str}")
end

# Assert that a line which ends with a , or \ is incomplete.
str !~ /[,\\]\s*\z/
# Assert that a line which ends with a , or \ but not with $\ is incomplete.
str !~ /(,|[^\$]\\)\s*\z/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use (?:...) in order not to create a captured group.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this change might break $$. Could you please check?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MethodSource.complete_expression?('$$') was true before this patch and is also true after this patch.

rescue IncompleteExpression
false
ensure
Expand Down
4 changes: 4 additions & 0 deletions test/test_code_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@
}.should.raise(SyntaxError)
end
end

it "should consider as complete lines ending with $\\" do
@tester.complete_expression?('$\\').should == true
end
end