Don't sanitize anchor elements with no href (#16667)
* If href is nil, allow node * Add unit test showing no change My first pass had the `<a>` within an h1 content, but the scrubber added a newline after the closing a tag?
This commit is contained in:
parent
40639ea602
commit
a052b16015
2 changed files with 7 additions and 1 deletions
|
|
@ -8,6 +8,6 @@ class FeedMarkdownScrubber < Rails::Html::PermitScrubber
|
|||
def allowed_node?(node)
|
||||
return true if tags.include?(node.name) && node.name != "a"
|
||||
|
||||
node.name == "a" && !node["href"].start_with?("#")
|
||||
node.name == "a" && !node["href"]&.start_with?("#")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -57,4 +57,10 @@ RSpec.describe FeedMarkdownScrubber, type: :permit_scrubber do
|
|||
clean = sanitize(bad_html, scrubber: described_class.new)
|
||||
expect(clean).to eq(good_html)
|
||||
end
|
||||
|
||||
it "does not scrub anchors with no link" do
|
||||
good_html = "I put an anchor <a>here</a>"
|
||||
clean = sanitize(good_html, scrubber: described_class.new)
|
||||
expect(clean).to eq(good_html)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue