Skip to content

Commit cacb767

Browse files
committed
Validate conditional expressions
1 parent 57e8a68 commit cacb767

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/pry-debugger/breakpoints.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ module Breakpoints
1111
# Add a new breakpoint.
1212
def add(file, line, expression = nil)
1313
raise ArgumentError, 'Invalid file!' unless File.exist?(file)
14+
validate_expression expression
15+
1416
Pry.processor.debugging = true
1517
Debugger.add_breakpoint(File.expand_path(file), line, expression)
1618
end
1719

1820
# Change the conditional expression for a breakpoint.
1921
def change(id, expression = nil)
22+
validate_expression expression
23+
2024
breakpoint = find_by_id(id)
2125
breakpoint.expr = expression
2226
breakpoint
@@ -79,5 +83,10 @@ def change_status(id, enabled = true)
7983
breakpoint.enabled = enabled
8084
breakpoint
8185
end
86+
87+
def validate_expression(expression)
88+
# `complete_expression?` throws a SyntaxError on invalid input.
89+
expression && Pry::Code.complete_expression?(expression)
90+
end
8291
end
8392
end

0 commit comments

Comments
 (0)