mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-15 11:21:42 +00:00
Use Html2Text to generate plaintext for keyword mutes. #236.
This allows us to match URLs inside link hrefs.
This commit is contained in:
parent
9105b0c954
commit
f1f67c46c5
|
@ -1,16 +1,12 @@
|
||||||
require 'htmlentities'
|
require 'html2text'
|
||||||
|
|
||||||
class Glitch::KeywordMuteHelper
|
class Glitch::KeywordMuteHelper
|
||||||
include ActionView::Helpers::SanitizeHelper
|
|
||||||
|
|
||||||
attr_reader :text_matcher
|
attr_reader :text_matcher
|
||||||
attr_reader :tag_matcher
|
attr_reader :tag_matcher
|
||||||
attr_reader :entity_decoder
|
|
||||||
|
|
||||||
def initialize(receiver_id)
|
def initialize(receiver_id)
|
||||||
@text_matcher = Glitch::KeywordMute.text_matcher_for(receiver_id)
|
@text_matcher = Glitch::KeywordMute.text_matcher_for(receiver_id)
|
||||||
@tag_matcher = Glitch::KeywordMute.tag_matcher_for(receiver_id)
|
@tag_matcher = Glitch::KeywordMute.tag_matcher_for(receiver_id)
|
||||||
@entity_decoder = HTMLEntities.new
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches?(status)
|
def matches?(status)
|
||||||
|
@ -26,6 +22,6 @@ class Glitch::KeywordMuteHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_text(text)
|
def prepare_text(text)
|
||||||
entity_decoder.decode(strip_tags(text)).tap { |x| puts x }
|
Html2Text.convert(text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,5 +39,12 @@ RSpec.describe Glitch::KeywordMuteHelper do
|
||||||
|
|
||||||
expect(helper.matches?(status)).to be true
|
expect(helper.matches?(status)).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'matches link hrefs in HTML text' do
|
||||||
|
status = Fabricate(:status, text: '<p><a href="https://example.com/it-was-milk">yep</a></p>')
|
||||||
|
Glitch::KeywordMute.create!(account: alice, keyword: 'milk')
|
||||||
|
|
||||||
|
expect(helper.matches?(status)).to be true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue