Escape HTML entities in commit messages
This commit is contained in:
parent
2b3313697f
commit
bed60b8c47
4 changed files with 12 additions and 8 deletions
5
changelogs/unreleased/dm-escape-commit-message.yml
Normal file
5
changelogs/unreleased/dm-escape-commit-message.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Escape HTML entities in commit messages
|
||||||
|
merge_request:
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -5,7 +5,7 @@ module Banzai
|
||||||
# Text filter that escapes these HTML entities: & " < >
|
# Text filter that escapes these HTML entities: & " < >
|
||||||
class HtmlEntityFilter < HTML::Pipeline::TextFilter
|
class HtmlEntityFilter < HTML::Pipeline::TextFilter
|
||||||
def call
|
def call
|
||||||
ERB::Util.html_escape_once(text)
|
ERB::Util.html_escape(text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,5 +20,9 @@ describe EventsHelper do
|
||||||
it 'handles nil values' do
|
it 'handles nil values' do
|
||||||
expect(helper.event_commit_title(nil)).to eq('')
|
expect(helper.event_commit_title(nil)).to eq('')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not escape HTML entities' do
|
||||||
|
expect(helper.event_commit_title("foo & bar")).to eq("foo & bar")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,17 +3,12 @@ require 'spec_helper'
|
||||||
describe Banzai::Filter::HtmlEntityFilter do
|
describe Banzai::Filter::HtmlEntityFilter do
|
||||||
include FilterSpecHelper
|
include FilterSpecHelper
|
||||||
|
|
||||||
let(:unescaped) { 'foo <strike attr="foo">&&&</strike>' }
|
let(:unescaped) { 'foo <strike attr="foo">&&</strike>' }
|
||||||
let(:escaped) { 'foo <strike attr="foo">&&&</strike>' }
|
let(:escaped) { 'foo <strike attr="foo">&&amp;&</strike>' }
|
||||||
|
|
||||||
it 'converts common entities to their HTML-escaped equivalents' do
|
it 'converts common entities to their HTML-escaped equivalents' do
|
||||||
output = filter(unescaped)
|
output = filter(unescaped)
|
||||||
|
|
||||||
expect(output).to eq(escaped)
|
expect(output).to eq(escaped)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not double-escape' do
|
|
||||||
escaped = ERB::Util.html_escape("Merge branch 'blabla' into 'master'")
|
|
||||||
expect(filter(escaped)).to eq(escaped)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue