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

#text should only render HTML elements #221

Closed
weiqingtoh opened this issue Dec 8, 2021 · 1 comment · Fixed by #222
Closed

#text should only render HTML elements #221

weiqingtoh opened this issue Dec 8, 2021 · 1 comment · Fixed by #222

Comments

@weiqingtoh
Copy link

Not sure if this is an issue, but a question here - is it intended for #text to show text within non visible HTML tags? It seems like we are still displaying for <style> tags as well as HTML comment tags <!-- Some text>.

Thank you!

Loofah.fragment("<style> some css</style><p> some text</p>").text
=> " some css some text"
 Loofah.fragment("<style> some css</style> <!-- some HTML comment --><p> some text</p>").text
=> " some css  some HTML comment  some text"
@flavorjones
Copy link
Owner

@weiqingtoh Thanks for asking this question! I think this is a bug in Loofah's implementation of Node#text:

html_frag = "<style> some css</style> <!-- some HTML comment --><p> some text</p>"

Nokogiri::HTML::DocumentFragment.parse(html_frag).text
=> " some css  some text"

Loofah.fragment(html_frag).text
=> " some css  some HTML comment  some text"

Nokogiri uses a libxml2 function to serialize. Loofah overrides this method but is including all children, not just visible elements.

I'll work on a fix!

@flavorjones flavorjones changed the title Should #text render text with non-visible HTML tags #text should only render HTML elements Dec 8, 2021
flavorjones added a commit that referenced this issue Dec 10, 2021
Previously any comment nodes that were top-level children of the
fragment were serialized.

Closes #221
flavorjones added a commit that referenced this issue Dec 10, 2021
Previously any comment nodes that were top-level children of the
fragment were serialized.

Closes #221
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 a pull request may close this issue.

2 participants