Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/models/admin/ng_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,23 @@ 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
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)
Expand Down
2 changes: 2 additions & 0 deletions app/models/admin/ng_word.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/activitypub/activity/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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! <a href="https://hello.org">OH GOOD</a>' }

it 'creates status' do
expect(sender.statuses.first).to_not be_nil
Expand Down Expand Up @@ -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 <a href="https://amely.net/">GOOD LINK</a>' }
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
Expand Down
Loading