Skip to content

Commit 6d58999

Browse files
committed
Expect escaped backslashes in expressions to inspect
1 parent 83a7a2f commit 6d58999

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

lib/ruby-debug-ide/command.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def timeout(sec)
108108
def debug_eval(str, b = get_binding)
109109
begin
110110
str = str.to_s
111+
to_inspect = unescape_incoming(str)
111112
max_time = Debugger.evaluation_timeout
112-
to_inspect = str.gsub(/\\n/, "\n")
113113
@printer.print_debug("Evaluating #{str} with timeout after %i sec", max_time)
114114
timeout(max_time) do
115115
eval(to_inspect, b)
@@ -120,6 +120,11 @@ def debug_eval(str, b = get_binding)
120120
end
121121
end
122122

123+
def unescape_incoming(str)
124+
str.gsub(/(?<backsl_escapes>(?:^|[^\\])(?:\\\\)*)\\n/, "\\k<backsl_escapes>\n")
125+
.gsub(/\\\\/, '\\')
126+
end
127+
123128
def debug_silent_eval(str)
124129
begin
125130
str = str.to_s

lib/ruby-debug-ide/commands/expression_info.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def regexp
99
end
1010

1111
def execute
12-
string_to_parse = @match.post_match.gsub("\\n", "\n") + "\n\n\n"
12+
string_to_parse = unescape_incoming(@match.post_match) + "\n\n\n"
1313
total_lines = string_to_parse.count("\n") + 1
1414

1515
lexer = RubyLex.new

test-base/inspect_test.rb

+20
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,25 @@ def test_inspect_multiline_expression
6868
send_cont
6969
end
7070

71+
def test_inspect_escaping_escaped_newlines
72+
create_socket ["sleep 0.1"]
73+
run_to_line(1)
74+
75+
send_ruby('v inspect "\\\\n".size')
76+
variable = read_variables
77+
assert_equal(1, variables.length, "There is one variable returned.")
78+
assert_equal(1, variables[0].value, "There is one char (newline)")
79+
80+
send_ruby('v inspect "\\\\\\n".size')
81+
variable = read_variables
82+
assert_equal(1, variables.length, "There is one variable returned.")
83+
assert_equal(0, variables[0].value, "There are no chars, it's line continuation here")
84+
85+
send_ruby('v inspect "\\\\\\\\\\n".size')
86+
variable = read_variables
87+
assert_equal(1, variables.length, "There is one variable returned.")
88+
assert_equal(2, variables[0].value, "There are two chars: escaped backslash and newline")
89+
end
90+
7191
end
7292

0 commit comments

Comments
 (0)