diff --git a/lib/discourse_diff.rb b/lib/discourse_diff.rb index 60bdd3f064..91e4115fed 100644 --- a/lib/discourse_diff.rb +++ b/lib/discourse_diff.rb @@ -261,8 +261,7 @@ class DiscourseDiff end def characters(string) - string = CGI::escapeHTML(string) - @tokens.concat string.scan(/(\W|\w+[ \t]*)/).flatten + @tokens.concat string.scan(/\W|\w+[ \t]*/).map { |x| CGI::escapeHTML(x) } end end diff --git a/spec/components/discourse_diff_spec.rb b/spec/components/discourse_diff_spec.rb index c21737ad85..53150a5dfb 100644 --- a/spec/components/discourse_diff_spec.rb +++ b/spec/components/discourse_diff_spec.rb @@ -49,6 +49,12 @@ describe DiscourseDiff do expect(DiscourseDiff.new(before, after).inline_html).to eq("

this is the first paragraph

this is the second paragraph

") end + it "does not break diff on character references" do + before = "

'

" + after = "

" + expect(DiscourseDiff.new(before, after).inline_html).to eq("

'

") + end + end describe "side_by_side_html" do @@ -86,6 +92,12 @@ describe DiscourseDiff do expect(DiscourseDiff.new(before, after).side_by_side_html).to eq("

this is the first paragraph

this is the second paragraph

this is the second paragraph

") end + it "does not break diff on character references" do + before = "

'

" + after = "

" + expect(DiscourseDiff.new(before, after).side_by_side_html).to eq("

'

") + end + end describe "side_by_side_markdown" do