Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds UNSAFE option to CommonMarker usage where needed #304

Merged
merged 1 commit into from Nov 8, 2018
Merged

Adds UNSAFE option to CommonMarker usage where needed #304

merged 1 commit into from Nov 8, 2018

Conversation

diachini
Copy link
Contributor

@diachini diachini commented Nov 6, 2018

With the release of commonmarker 0.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.

Usage from my app:

# without the `unsafe` option being specified:
> HTML::Pipeline.new([HTML::Pipeline::MarkdownFilter])
    .call('<a href="http://example.com">Link</a>')
=> {:output=>"<p><!-- raw HTML omitted -->Link<!-- raw HTML omitted --></p>"}

# with the `unsafe` option being specified:
> HTML::Pipeline.new([HTML::Pipeline::MarkdownFilter])
    .call('<a href="http://example.com">Link</a>', unsafe: true)
=> {:output=>"<p><a href=\"http://example.com\">Link</a></p>"}

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.
@@ -23,6 +23,7 @@ def initialize(text, context = nil, result = nil)
def call
options = [:GITHUB_PRE_LANG]
options << :HARDBREAKS if context[:gfm] != false
options << :UNSAFE if context[:unsafe]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if it would be desired to be unsafe by default (like gfm) - so I went with "No", for now.

@gjtorikian
Copy link
Owner

Thanks so much!

@gjtorikian gjtorikian merged commit e273878 into gjtorikian:master Nov 8, 2018
@diachini diachini deleted the allow_commonmarker_unsafe_option branch November 9, 2018 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants