Strip style elements from snippets for #3146 #3268
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #3146
This uses Nokogiri to remove the
style
element and its contents from collections'intro_block
s when they're being shown as a snippet on the Find a Project page, because previously the contents of thestyle
element were showing up instead of the collection's description.With this PR, there is no HTML in the snippet and ampersands show up correctly.
strip_tags(intro_block)
vs.Loofah.fragment(intro_block).text
We were initially using
strip_tags
to remove HTML tags from the collection's description and shorten it for the Find a Project page.strip_tags
automatically removed thestyle
element and its contents, so there was no HTML shown like there is in this issue. However,strip_tags
escaped special characters like&
to&
, which we did not want.So we switched to
Loofah.fragment.text
, which gives the option to notencode_special_chars
. However,Loofah.fragment.text
does not remove the contents of thestyle
element, making this PR necessary.Changes made
I added a helper function
to_snippet(intro_block)
that does the following:style
element and its contents from the intro blockintro_block
usingLoofah.fragment.text
intro_block
2 and 3 were previously done in the view, but I moved them to this helper function to consolidate everything into one place, as this sequence is repeated in multiple places in the Find a Project view.