Permalink
Browse files

Validate conditional expressions

  • Loading branch information...
1 parent 57e8a68 commit cacb7676eadd0327e261f9e36c64aa69e9733aed @nixme committed Jun 12, 2012
Showing with 9 additions and 0 deletions.
  1. +9 −0 lib/pry-debugger/breakpoints.rb
@@ -11,12 +11,16 @@ module Breakpoints
# Add a new breakpoint.
def add(file, line, expression = nil)
raise ArgumentError, 'Invalid file!' unless File.exist?(file)
+ validate_expression expression
+
Pry.processor.debugging = true
Debugger.add_breakpoint(File.expand_path(file), line, expression)
end
# Change the conditional expression for a breakpoint.
def change(id, expression = nil)
+ validate_expression expression
+
breakpoint = find_by_id(id)
breakpoint.expr = expression
breakpoint
@@ -79,5 +83,10 @@ def change_status(id, enabled = true)
breakpoint.enabled = enabled
breakpoint
end
+
+ def validate_expression(expression)
+ # `complete_expression?` throws a SyntaxError on invalid input.
+ expression && Pry::Code.complete_expression?(expression)
+ end
end
end

0 comments on commit cacb767

Please sign in to comment.