Skip to content

Commit

Permalink
Edge case, handle backspace characters
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Aug 6, 2010
1 parent e8cbcdc commit 7366450
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/irb/source.rb
Expand Up @@ -191,7 +191,7 @@ def on_tstring_beg(token)
end

def on_tstring_end(token)
if tokens_match?(@in_string, token)
if @in_string && tokens_match?(@in_string, token)
@in_string = nil
@level -= 1
end
Expand Down
18 changes: 18 additions & 0 deletions spec/source_spec.rb
Expand Up @@ -191,19 +191,26 @@ def reflect(source)
["{ :foo => ", " :bar }"],
["[ 1", ", 2 ]"],

["'", "'"],
["' ", " '"],
["'foo ", " bar'"],
["' foo ", " bar '"],

['"', '"'],
['" ', ' "'],
['"foo ', ' bar"'],
['" foo ', ' bar "'],

["%{", "}"],
["%{ ", " }"],
["%{foo ", " bar}"],
["%{ foo ", " bar }"],
["%(foo ", " bar)"],
["%( foo ", " bar )"],
["%[ foo ", " bar ]"],
["%[foo ", " bar]"],

["%w{ ", " }"],
["%w{foo ", " bar}"],
["%w{ foo ", " bar }"],
["%w(foo ", " bar)"],
Expand Down Expand Up @@ -234,4 +241,15 @@ def reflect(source)
reflect("#{open}\n#{close}").code_block?.should == true
end
end

it "handles cases that contain backspaces" do
[
["%{", "\b"],
["%w{", "\b"],
["%r{", "\b"],
].each do |open, close|
reflect("#{open}\n#{close}").level.should == 1
reflect("#{open}\n#{close}").code_block?.should == false
end
end
end

0 comments on commit 7366450

Please sign in to comment.