notes: allow all elements to have style/title attributes.

This commit is contained in:
evazion
2017-06-15 20:34:38 -05:00
parent 85e32b5eb2
commit 869ccad6ba
2 changed files with 21 additions and 8 deletions

View File

@@ -1,17 +1,25 @@
module NoteSanitizer
ALLOWED_ELEMENTS = %w(
code center tn h1 h2 h3 h4 h5 h6 a span div blockquote br p ul li ol em
strong small big b i font u s pre ruby rb rt rp
)
ALLOWED_ATTRIBUTES = {
:all => %w(style title),
"a" => %w(href),
"span" => %w(class),
"div" => %w(class align),
"p" => %w(class align),
"font" => %w(color size),
}
def self.sanitize(text)
text.gsub!(/<( |-|3|:|>|\Z)/, "&lt;\\1")
Sanitize.clean(
text,
:elements => %w(code center tn h1 h2 h3 h4 h5 h6 a span div blockquote br p ul li ol em strong small big b i font u s pre ruby rb rt rp),
:attributes => {
"a" => %w(href title style),
"span" => %w(class style),
"div" => %w(class style align),
"p" => %w(class style align),
"font" => %w(color size style)
},
:elements => ALLOWED_ELEMENTS,
:attributes => ALLOWED_ATTRIBUTES,
:protocols => {
"a" => {
"href" => ["http", "https", :relative]

View File

@@ -11,5 +11,10 @@ class NoteSanitizerTest < ActiveSupport::TestCase
body = '<p style="background-image: url(http://www.google.com);">test</p>'
assert_equal("<p>test</p>", NoteSanitizer.sanitize(body))
end
should "allow style attributes on every tag" do
body = '<p style="font-size: 1em;">test</p>'
assert_equal('<p style="font-size: 1em;">test</p>', NoteSanitizer.sanitize(body))
end
end
end