Skip to content

Commit 92fce0d

Browse files
author
diachini
committed
Adds UNSAFE option to CommonMarker usage where needed
With the [release of commonmarker 0.18.0](https://github.com/gjtorikian/commonmarker/releases/tag/v0.18.0), HTML safety was introduced as a default (to avoid XSS). But if someone _wants_ to allow unsafe elements in their markdown, they should be able to pass that option down to CommonMarker through html-pipeline.
1 parent 642e922 commit 92fce0d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/html/pipeline/markdown_filter.rb

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def initialize(text, context = nil, result = nil)
2323
def call
2424
options = [:GITHUB_PRE_LANG]
2525
options << :HARDBREAKS if context[:gfm] != false
26+
options << :UNSAFE if context[:unsafe]
2627
extensions = context.fetch(
2728
:commonmarker_extensions,
2829
%i[table strikethrough tagfilter autolink]

test/html/pipeline/markdown_filter_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ def test_fenced_code_blocks_with_language
5252
def test_standard_extensions
5353
iframe = "<iframe src='http://www.google.com'></iframe>"
5454
iframe_escaped = "&lt;iframe src='http://www.google.com'>&lt;/iframe>"
55-
doc = MarkdownFilter.new(iframe).call
55+
doc = MarkdownFilter.new(iframe, unsafe: true).call
5656
assert_equal(doc, iframe_escaped)
5757
end
5858

5959
def test_changing_extensions
6060
iframe = "<iframe src='http://www.google.com'></iframe>"
61-
doc = MarkdownFilter.new(iframe, commonmarker_extensions: []).call
61+
doc = MarkdownFilter.new(iframe, commonmarker_extensions: [], unsafe: true).call
6262
assert_equal(doc, iframe)
6363
end
6464
end
6565

6666
class GFMTest < Minitest::Test
6767
def gfm(text)
68-
MarkdownFilter.call(text, gfm: true)
68+
MarkdownFilter.call(text, gfm: true, unsafe: true)
6969
end
7070

7171
def test_not_touch_single_underscores_inside_words

0 commit comments

Comments
 (0)