Change: NGルール・NGワードのテキストマッチはHTMLタグを除外する (#623)

This commit is contained in:
KMY(雪あすか) 2024-03-01 12:01:09 +09:00 committed by GitHub
parent bc07ebef3d
commit dc3aabb4f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 6 deletions

View file

@ -176,7 +176,7 @@ class Admin::NgRule
end end
def detect_keyword?(text, arr) def detect_keyword?(text, arr)
Admin::NgRule.detect_keyword?(text, arr) Admin::NgRule.detect_keyword?(text, arr, local: @account.local?)
end end
class << self class << self
@ -184,14 +184,15 @@ class Admin::NgRule
text.delete("\r").split("\n") text.delete("\r").split("\n")
end end
def detect_keyword(text, arr) def detect_keyword(text, arr, local: true)
arr = string_to_array(arr) if arr.is_a?(String) arr = string_to_array(arr) if arr.is_a?(String)
text = PlainTextFormatter.new(text, false).to_s unless local
arr.detect { |word| include?(text, word) ? word : nil } arr.detect { |word| include?(text, word) ? word : nil }
end end
def detect_keyword?(text, arr) def detect_keyword?(text, arr, local: true)
detect_keyword(text, arr).present? detect_keyword(text, arr, local: local).present?
end end
def include?(text, word) def include?(text, word)

View file

@ -3,12 +3,14 @@
class Admin::NgWord class Admin::NgWord
class << self class << self
def reject?(text, **options) def reject?(text, **options)
text = PlainTextFormatter.new(text, false).to_s if options[:uri].present?
hit_word = ng_words.detect { |word| include?(text, word) ? word : nil } hit_word = ng_words.detect { |word| include?(text, word) ? word : nil }
record!(:ng_words, text, hit_word, options) if hit_word.present? record!(:ng_words, text, hit_word, options) if hit_word.present?
hit_word.present? hit_word.present?
end end
def stranger_mention_reject?(text, **options) def stranger_mention_reject?(text, **options)
text = PlainTextFormatter.new(text, false).to_s if options[:uri].present?
hit_word = ng_words_for_stranger_mention.detect { |word| include?(text, word) ? word : nil } hit_word = ng_words_for_stranger_mention.detect { |word| include?(text, word) ? word : nil }
record!(:ng_words_for_stranger_mention, text, hit_word, options) if hit_word.present? record!(:ng_words_for_stranger_mention, text, hit_word, options) if hit_word.present?
hit_word.present? hit_word.present?

View file

@ -1802,7 +1802,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
context 'when not contains ng words' do context 'when not contains ng words' do
let(:content) { 'ohagi, world!' } let(:content) { 'ohagi, world! <a href="https://hello.org">OH GOOD</a>' }
it 'creates status' do it 'creates status' do
expect(sender.statuses.first).to_not be_nil expect(sender.statuses.first).to_not be_nil
@ -2052,7 +2052,7 @@ RSpec.describe ActivityPub::Activity::Create do
context 'when ng rule is set' do context 'when ng rule is set' do
let(:custom_before) { true } let(:custom_before) { true }
let(:content) { 'Lorem ipsum' } let(:content) { 'Lorem ipsum <a href="https://amely.net/">GOOD LINK</a>' }
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,