Project

General

Profile

Feature #44585 » 0003-Allow-the-same-CSS-properties-in-the-style-attribute.patch

Go MAEDA, 2026-10-10 11:13

View differences:

lib/redmine/wiki_formatting/sanitization_filter.rb
TABLE = 'table'
TABLE_SECTIONS = Set.new(%w[thead tbody tfoot].freeze)
# Same properties as the ones accepted by RedCloth3::STYLES_RE
STYLE_PROPERTY_RE = /\A(color|(min-|max-)?(width|height)|border|background|padding|margin|font|text|float)(-[a-z]+)*\z/
STYLE_PROPERTIES =
(Sanitize::Config::RELAXED[:css][:properties].grep(STYLE_PROPERTY_RE) + %w[line-height vertical-align]).freeze
# The main sanitization allowlist. Only these elements and attributes are
# allowed through by default.
ALLOWLIST = {
......
}
].freeze,
:css => {
:properties => %w[
color background-color
width min-width max-width
height min-height max-height
padding padding-left padding-right padding-top padding-bottom
margin margin-left margin-right margin-top margin-bottom
border border-left border-right border-top border-bottom border-radius border-style border-collapse border-spacing
font font-style font-variant font-weight font-stretch font-size line-height font-family
text-align text-decoration
float
].freeze
:properties => STYLE_PROPERTIES
}
}.freeze
lib/redmine/wiki_formatting/textile/sanitization_filter.rb
ALLOWED_CLASS_RE = /\A(wiki-class-\S+|external|email|footnote)\z/
ALLOWED_ID_RE = /\A(wiki-id-\S+|fn\d+)\z/
# Same properties as the ones accepted by RedCloth3::STYLES_RE
STYLE_PROPERTY_RE = /\A(color|(min-|max-)?(width|height)|border|background|padding|margin|font|text|float)(-[a-z]+)*\z/
STYLE_PROPERTIES =
(Sanitize::Config::RELAXED[:css][:properties].grep(STYLE_PROPERTY_RE) + %w[vertical-align]).freeze
private
def default_allowlist
allowlist = super
allowlist[:attributes][:all] += %w[class id]
allowlist[:css][:properties] |= STYLE_PROPERTIES
allowlist
end
test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb
end
def test_should_support_html_tables
text = '<table style="background: red"><tr><td>Cell</td></tr></table>'
text = '<table style="position: fixed"><tr><td>Cell</td></tr></table>'
assert_equal '<table><tbody><tr><td>Cell</td></tr></tbody></table>', to_html(text)
end
test/unit/lib/redmine/wiki_formatting/common_mark/sanitization_filter_test.rb
'<span style="color: #333; background: url(\'https://example.com/evil.svg\')">hello</span>"',
'<span style="color: #333; ">hello</span>"'
],
[
'<span style="background: #fdd; vertical-align: top; border-top-left-radius: 4px;">hello</span>',
'<span style="background: #fdd; vertical-align: top; border-top-left-radius: 4px;">hello</span>'
],
[
'<img src="photo.jpg" style="min-width: 100px; max-width: 200px; min-height: 100px; max-height: 200px;">',
'<img src="photo.jpg" style="min-width: 100px; max-width: 200px; min-height: 100px; max-height: 200px;">'
(3-3/3)