File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
app/services/discourse_translator Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -41,11 +41,27 @@ 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='/u /cat' >cat</a >"
4646 expect ( DiscourseTranslator ::Base . text_for_detection ( post ) ) . to eq ( "" )
4747 end
4848
49+ it "strips lightbox anchor tags" do
50+ post . cooked = "<a class='lightbox' href='http://cloudfront.net/image.png' />"
51+ expect ( DiscourseTranslator ::Base . text_for_detection ( post ) ) . to eq ( "" )
52+ end
53+
54+ it "leaves other anchor tags alone" do
55+ cooked = <<~HTML
56+ < p >
57+ < a href ="http://cat.com/image.png "> </ a >
58+ < a class ="derp " href ="http://cat.com/image.png "> </ a >
59+ </ p >
60+ HTML
61+ post . cooked = cooked
62+ expect ( DiscourseTranslator ::Base . text_for_detection ( post ) ) . to eq ( cooked )
63+ end
64+
4965 it "truncates to DETECTION_CHAR_LIMIT of 1000" do
5066 post . cooked = "a" * 1001
5167 expect ( DiscourseTranslator ::Base . text_for_detection ( post ) . length ) . to eq ( 1000 )
You can’t perform that action at this time.
0 commit comments