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

Workaround for encode_special_chars #48

Closed
TALlama opened this issue Jan 26, 2016 · 1 comment
Closed

Workaround for encode_special_chars #48

TALlama opened this issue Jan 26, 2016 · 1 comment

Comments

@TALlama
Copy link

TALlama commented Jan 26, 2016

I'm trying to take an HTML fragment and output it in a non-HTML context (CSV, to be specific). As such, I want to "slurp out" the text unchanged but strip tags completely, which I used to be able to do but in 1.0.3 I now have to decode HTML entities outside the sanitizer.

Before 1.0.3, You could do:

Rails::Html::FullSanitizer.new.sanitize(%{"I would like," <a href="etc">John</a> said, "a Black & Tan."}, encode_special_chars: false)
=> %{"I would like," John said, "a Black & Tan."}

But now in 1.0.3, there is no way to strip tags without also HTML-encoding the special characters:

Rails::Html::FullSanitizer.new.sanitize(%{"I would like," <a href="etc">John</a> said, "a Black & Tan."}, encode_special_chars: false)
=> "\"I would like,\" John said, \"a Black &amp; Tan.\""

(that encode_special_characters is totally ignored without any warning is also concerning; a deprecation message or an error would be nice)

I understand that this was because we were un-escaping already-escaped special characters, but I don't understand why this means we now have no way to keep our not-escaped special characters not-escaped.

@rafaelfranca
Copy link
Member

HTML sanitizing is for HTML contexts. There is not way to safely not escape HTML entities without reintroducing the security issue. You can fallback to loofah if you want to keep this behavior.

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

No branches or pull requests

2 participants