Skip to content

Commit a734b30

Browse files
committed
Limit to mention anchor tags
1 parent ec73f54 commit a734b30

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

app/services/discourse_translator/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def self.language_supported?(detected_lang)
7575
def self.strip_tags_for_detection(detection_text)
7676
html_doc = Nokogiri::HTML::DocumentFragment.parse(detection_text)
7777
html_doc.css("img").remove
78-
html_doc.css("a").remove
78+
html_doc.css("a.mention").remove
7979
html_doc.to_html
8080
end
8181

spec/services/base_spec.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,22 @@ class EmptyTranslator < DiscourseTranslator::Base
4141
expect(DiscourseTranslator::Base.text_for_detection(post)).to eq("")
4242
end
4343

44-
it "strips anchor tags" do
45-
post.cooked = "<a href='http://cat.com/image.png' />"
44+
it "strips @ mention anchor tags" do
45+
post.cooked = "<a class='mention' href='http://cat.com/image.png' />"
4646
expect(DiscourseTranslator::Base.text_for_detection(post)).to eq("")
4747
end
4848

49+
it "leaves other anchor tags alone" do
50+
cooked = <<~HTML
51+
<p>
52+
<a href="http://cat.com/image.png"></a>
53+
<a class="derp" href="http://cat.com/image.png"></a>
54+
</p>
55+
HTML
56+
post.cooked = cooked
57+
expect(DiscourseTranslator::Base.text_for_detection(post)).to eq(cooked)
58+
end
59+
4960
it "truncates to DETECTION_CHAR_LIMIT of 1000" do
5061
post.cooked = "a" * 1001
5162
expect(DiscourseTranslator::Base.text_for_detection(post).length).to eq(1000)

0 commit comments

Comments
 (0)