Skip to content

Commit

Permalink
Fix escaping of term codes in Terminal256 formatter (#1404)
Browse files Browse the repository at this point in the history
This commit fixes a bug in escaping term codes around `\n` in the
Terminal256 formatter.
  • Loading branch information
jneen authored and pyrmont committed Jan 23, 2020
1 parent 22ac678 commit 439d9e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/rouge/formatters/terminal256.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def bg

def stream_value(val, &b)
yield style_string
yield val.gsub("\n", "#{reset_string}\n#{style_string}")
.gsub("\e", "\\e")
yield val.gsub("\e", "\\e")
.gsub("\n", "#{reset_string}\n#{style_string}")
yield reset_string
end

Expand Down
5 changes: 4 additions & 1 deletion spec/lexers/escape_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

describe 'terminal256' do
let(:formatter) { Rouge::Formatters::Terminal256.new }
let(:text) { %({ "foo": <!\e123!> }) }
let(:text) { %({ "foo": \n <!\e123!> }) }

it 'unescapes' do
assert { result =~ /\e123/ }

# shouldn't escape the term codes around \n
assert { result =~ /\n\e/ }
end
end
end

0 comments on commit 439d9e5

Please sign in to comment.