From dc3aabb4f451075cedc3149ea783427a491f75e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KMY=EF=BC=88=E9=9B=AA=E3=81=82=E3=81=99=E3=81=8B=EF=BC=89?= Date: Fri, 1 Mar 2024 12:01:09 +0900 Subject: [PATCH] =?UTF-8?q?Change:=20NG=E3=83=AB=E3=83=BC=E3=83=AB?= =?UTF-8?q?=E3=83=BBNG=E3=83=AF=E3=83=BC=E3=83=89=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=AD=E3=82=B9=E3=83=88=E3=83=9E=E3=83=83=E3=83=81=E3=81=AF?= =?UTF-8?q?HTML=E3=82=BF=E3=82=B0=E3=82=92=E9=99=A4=E5=A4=96=E3=81=99?= =?UTF-8?q?=E3=82=8B=20(#623)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/admin/ng_rule.rb | 9 +++++---- app/models/admin/ng_word.rb | 2 ++ spec/lib/activitypub/activity/create_spec.rb | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/admin/ng_rule.rb b/app/models/admin/ng_rule.rb index 8746457b808725..54ca39b4c9d0cd 100644 --- a/app/models/admin/ng_rule.rb +++ b/app/models/admin/ng_rule.rb @@ -176,7 +176,7 @@ def value_over_threshold?(_reason, value, expected) end def detect_keyword?(text, arr) - Admin::NgRule.detect_keyword?(text, arr) + Admin::NgRule.detect_keyword?(text, arr, local: @account.local?) end class << self @@ -184,14 +184,15 @@ def string_to_array(text) text.delete("\r").split("\n") end - def detect_keyword(text, arr) + def detect_keyword(text, arr, local: true) 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 } end - def detect_keyword?(text, arr) - detect_keyword(text, arr).present? + def detect_keyword?(text, arr, local: true) + detect_keyword(text, arr, local: local).present? end def include?(text, word) diff --git a/app/models/admin/ng_word.rb b/app/models/admin/ng_word.rb index 2a961d290349be..871909e316b0bf 100644 --- a/app/models/admin/ng_word.rb +++ b/app/models/admin/ng_word.rb @@ -3,12 +3,14 @@ class Admin::NgWord class << self 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 } record!(:ng_words, text, hit_word, options) if hit_word.present? hit_word.present? end 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 } record!(:ng_words_for_stranger_mention, text, hit_word, options) if hit_word.present? hit_word.present? diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index f5137b9fe64b2a..5c668f1e3abdcf 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -1802,7 +1802,7 @@ def activity_for_object(json) end context 'when not contains ng words' do - let(:content) { 'ohagi, world!' } + let(:content) { 'ohagi, world! OH GOOD' } it 'creates status' do expect(sender.statuses.first).to_not be_nil @@ -2052,7 +2052,7 @@ def activity_for_object(json) context 'when ng rule is set' do let(:custom_before) { true } - let(:content) { 'Lorem ipsum' } + let(:content) { 'Lorem ipsum GOOD LINK' } let(:object_json) do { id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,