diff --git a/app/services/search_indexer.rb b/app/services/search_indexer.rb index 1885a4c6f47..33d18b41c9a 100644 --- a/app/services/search_indexer.rb +++ b/app/services/search_indexer.rb @@ -337,6 +337,10 @@ class SearchIndexer if node["href"] == node.text || MENTION_CLASSES.include?(node["class"]) node.remove_attribute("href") end + + if node["class"] == "anchor" && node["href"].starts_with?("#") + node.remove_attribute("href") + end end html_scrubber = new diff --git a/spec/services/search_indexer_spec.rb b/spec/services/search_indexer_spec.rb index 180d1d0be82..b132c88080d 100644 --- a/spec/services/search_indexer_spec.rb +++ b/spec/services/search_indexer_spec.rb @@ -42,6 +42,12 @@ describe SearchIndexer do expect(scrubbed).to eq("http://meta.discourse.org/ link") end + it 'ignores autogenerated link anchors' do + html = "something special" + scrubbed = SearchIndexer::HtmlScrubber.scrub(html) + expect(scrubbed).to eq("something special") + end + it 'extracts @username from mentions' do html = '
' scrubbed = SearchIndexer::HtmlScrubber.scrub(html)