A platform for community discussion. Free, open, simple.
Escape values of HTML attributes
Dmitry Klimenskyd54b3398096a
diff --git a/lib/discourse_diff.rb b/lib/discourse_diff.rbindex cdf37870201..3887abe134c 100644--- a/lib/discourse_diff.rb+++ b/lib/discourse_diff.rb@@ -256,7 +256,7 @@ class DiscourseDiffUSELESS_TAGS = %w{html body}def start_element(name, attributes = [])return if USELESS_TAGS.include?(name)- attrs = attributes.map { |a| " #{a[0]}=\"#{a[1]}\"" }.join+ attrs = attributes.map { |a| " #{a[0]}=\"#{CGI::escapeHTML(a[1])}\"" }.join@tokens << "<#{name}#{attrs}>"enddiff --git a/spec/components/discourse_diff_spec.rb b/spec/components/discourse_diff_spec.rbindex d8683decc85..7f7d61ed9dc 100644--- a/spec/components/discourse_diff_spec.rb+++ b/spec/components/discourse_diff_spec.rb@@ -107,6 +107,11 @@ describe DiscourseDiff doexpect(DiscourseDiff.new(before, after).side_by_side_html).to eq("<div class=\"revision-content\"><p><del>'</del></p></div><div class=\"revision-content\"><p></p></div>")end+ it "escapes attribute values" do+ before = "<p data-attr='Some \"quoted\" string'></p>"+ after = "<p data-attr='Some \"quoted\" string'></p>"+ expect(DiscourseDiff.new(before, after).side_by_side_html).to eq("<div class=\"revision-content\"><p data-attr=\"Some "quoted" string\"></p></div><div class=\"revision-content\"><p data-attr=\"Some "quoted" string\"></p></div>")+ endenddescribe "side_by_side_markdown" do