Project

General

Profile

Feature #44634 ยป 0001-Escape-tags-that-commonmarker-escaped-with-its-tagfi.patch

Go MAEDA, 2026-10-18 07:38

View differences:

Gemfile
gem 'rack', '>= 3.1.3'
gem "stimulus-rails", "~> 1.3"
gem "importmap-rails", "~> 2.0"
gem 'commonmarker', '2.10.0'
gem 'commonmarker', '~> 2.10.0'
gem 'doorkeeper', '~> 5.9.6'
gem "bcrypt", require: false
gem "doorkeeper-i18n", "~> 5.2"
lib/redmine/wiki_formatting/common_mark/formatter.rb
commonmarker_extensions: {
table: true,
strikethrough: true,
tagfilter: true,
autolink: true,
footnotes: true,
header_ids: nil,
lib/redmine/wiki_formatting/common_mark/markdown_filter.rb
# does not allow for straightforward configuration of render and parsing
# options
class MarkdownFilter
# Tags that the commonmarker tagfilter extension escaped before its
# removal
DISALLOWED_RAW_HTML_TAG = %r{<(?=/?(?:title|textarea|style|xmp|iframe|noembed|noframes|script|plaintext)(?:[\s/>]|\z))}i
attr_reader :context
def initialize(text, context = nil)
......
parse: parse_options
}, plugins: plugins)
# Escape these tags in raw HTML as the commonmarker tagfilter
# extension did, since the extension was removed in commonmarker
# 2.10.1.
html.gsub!(DISALLOWED_RAW_HTML_TAG, '&lt;')
html.rstrip!
html
end
test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb
[
%[<p>sit<br>amet &lt;style&gt;.foo { color: #fff; }&lt;/style&gt; &lt;script&gt;alert("hello world");&lt;/script&gt;</p>],
%[sit<br/>amet <style>.foo { color: #fff; }</style> <script>alert("hello world");</script>]
],
[
%[<p>Unclosed &lt;script&gt; tag</p>\n<p>Next paragraph</p>],
%[Unclosed <script> tag\n\nNext paragraph]
]
].each do |expected, input|
assert_equal expected, to_html(input)
    (1-1/1)