Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
9 changes: 7 additions & 2 deletions lib/ruby-debug-ide/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def method_missing(meth, *args, &block)
def options
@options ||= {}
end

def unescape_incoming(str)
str.gsub(/((?:^|[^\\])(?:\\\\)*)\\n/, "\\1\n")
.gsub(/\\\\/, '\\')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure this type of continuation is allowed in 1.8
Please double-check.

end
end

def initialize(state, printer)
Expand Down Expand Up @@ -104,12 +109,12 @@ def timeout(sec)
y.kill if y and y.alive?
end
end

def debug_eval(str, b = get_binding)
begin
str = str.to_s
to_inspect = Command.unescape_incoming(str)
max_time = Debugger.evaluation_timeout
to_inspect = str.gsub(/\\n/, "\n")
@printer.print_debug("Evaluating #{str} with timeout after %i sec", max_time)
timeout(max_time) do
eval(to_inspect, b)
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-debug-ide/commands/expression_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def regexp
end

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

lexer = RubyLex.new
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-debug-ide/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Debugger
IDE_VERSION='0.4.27'
IDE_VERSION='0.4.28'
end
27 changes: 27 additions & 0 deletions test-base/inspect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,32 @@ def test_inspect_multiline_expression
send_cont
end

def test_inspect_unescaping_escaped_newlines
create_socket ["sleep 0.1"]
run_to_line(1)

send_ruby('v inspect "\\\\n".size')
variables = read_variables
assert_equal(1, variables.length, "There is one variable returned.")
assert_equal("1", variables[0].value, "There is one char (newline)")

send_ruby('v inspect "\\\\\\n".size')
variables = read_variables
assert_equal(1, variables.length, "There is one variable returned.")
assert_equal("0", variables[0].value, "There are no chars, it's line continuation here")

send_ruby('v inspect "\\\\\\\\\\n".size')
variables = read_variables
assert_equal(1, variables.length, "There is one variable returned.")
assert_equal("2", variables[0].value, "There are two chars: escaped backslash and newline")

send_ruby('v inspect \'"\\\\n\'.size')
variables = read_variables
assert_equal(1, variables.length, "There is one variable returned.")
assert_equal("3", variables[0].value, "There are three chars: quote, backslash and n")

send_cont
end

end

34 changes: 34 additions & 0 deletions test/ruby-debug/unescape_incoming_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'test/unit'
require 'ruby-debug-ide/command'

class UnescaperTest < Test::Unit::TestCase

def test_empty
do_test('', '')
do_test('a', 'a')
end

def test_newline
do_test('\n', "\n")
do_test('a\n', "a\n")
end

def test_escaped_newline
do_test('\\\\n', '\n')
do_test('a\\\\n', 'a\n')
end

def test_backslash_and_newline
do_test('\\\\\\n', "\\\n")
do_test('a\\\\\\n', "a\\\n")
end

def test_something
do_test('hello\nthere\\\\n', "hello\nthere\\n")
do_test('"\\\\\\n".size', "\"\\\n\".size")
end

def do_test(input, expected_result)
assert_equal(expected_result, Debugger::Command.unescape_incoming(input))
end
end