A platform for community discussion. Free, open, simple.
FIX: unify watched word boundary regex across Ruby and JS engines (#37965)
Régis Hanold01d060a8b14
diff --git a/app/serializers/site_serializer.rb b/app/serializers/site_serializer.rbindex e628a72759f..59edfa3149a 100644--- a/app/serializers/site_serializer.rb+++ b/app/serializers/site_serializer.rb@@ -269,7 +269,7 @@ class SiteSerializer < ApplicationSerializerenddef censored_regexp- WordWatcher.serialized_regexps_for_action(:censor, engine: :js)+ WordWatcher.serialized_regexps_for_action(:censor)enddef custom_emoji_translation@@ -285,11 +285,11 @@ class SiteSerializer < ApplicationSerializerenddef watched_words_replace- WordWatcher.regexps_for_action(:replace, engine: :js)+ WordWatcher.regexps_for_action(:replace)enddef watched_words_link- WordWatcher.regexps_for_action(:link, engine: :js)+ WordWatcher.regexps_for_action(:link)enddef categoriesdiff --git a/app/serializers/watched_word_list_serializer.rb b/app/serializers/watched_word_list_serializer.rbindex 42f89f326a6..68f3243b419 100644--- a/app/serializers/watched_word_list_serializer.rb+++ b/app/serializers/watched_word_list_serializer.rb@@ -18,7 +18,7 @@ class WatchedWordListSerializer < ApplicationSerializerdef compiled_regular_expressionsexpressions = {}actions.each do |action|- expressions[action] = WordWatcher.serialized_regexps_for_action(action, engine: :js)+ expressions[action] = WordWatcher.serialized_regexps_for_action(action)endexpressionsenddiff --git a/app/serializers/watched_word_serializer.rb b/app/serializers/watched_word_serializer.rbindex aff7cb7a7f7..a880a5cad2c 100644--- a/app/serializers/watched_word_serializer.rb+++ b/app/serializers/watched_word_serializer.rb@@ -11,7 +11,7 @@ class WatchedWordSerializer < ApplicationSerializer:htmldef regexp- WordWatcher.word_to_regexp(word, engine: :js)+ WordWatcher.word_to_regexp(word)enddef actiondiff --git a/app/services/word_watcher.rb b/app/services/word_watcher.rbindex c92be317236..46282e0e8b9 100644--- a/app/services/word_watcher.rb+++ b/app/services/word_watcher.rb@@ -53,15 +53,13 @@ class WordWatcherendend- def self.regexps_for_action(action, engine: :ruby)- cached_words_for_action(action)&.to_h do |_, attrs|- [word_to_regexp(attrs[:word], engine: engine), attrs]- end+ def self.regexps_for_action(action)+ cached_words_for_action(action)&.to_h { |_, attrs| [word_to_regexp(attrs[:word]), attrs] }end# This regexp is run in miniracer, and the client JS app# Make sure it is compatible with major browsers when changing- def self.compiled_regexps_for_action(action, engine: :ruby, raise_errors: false)+ def self.compiled_regexps_for_action(action, raise_errors: false)words = cached_words_for_action(action)return [] if words.blank?@@ -92,11 +90,7 @@ class WordWatchernext if regexp.blank?# Add word boundaries to the regexp for regular watched words- regexp =- match_word_regexp(- regexp,- engine: engine,- ) if !SiteSetting.watched_words_regular_expressions?+ regexp = match_word_regexp(regexp) if !SiteSetting.watched_words_regular_expressions?# Add case insensitive flag if neededbegin@@ -112,13 +106,11 @@ class WordWatcher.compactend- def self.serialized_regexps_for_action(action, engine: :ruby)- compiled_regexps_for_action(action, engine: engine).map do |r|- { r.source => { case_sensitive: !r.casefold? } }- end+ def self.serialized_regexps_for_action(action)+ compiled_regexps_for_action(action).map { |r| { r.source => { case_sensitive: !r.casefold? } } }end- def self.word_to_regexp(word, engine: :ruby, match_word: true)+ def self.word_to_regexp(word, match_word: true)if SiteSetting.watched_words_regular_expressions?regexp = wordregexp = "(#{regexp})" if match_word@@ -132,7 +124,7 @@ class WordWatcher# Convert wildcards to regexpregexp = regexp.gsub("\\*", '\S*')- regexp = match_word_regexp(regexp, engine: engine) if match_word+ regexp = match_word_regexp(regexp) if match_wordregexpendend@@ -294,19 +286,14 @@ class WordWatcher"Tibetan" => "\\u0F00-\\u0FFF",}.values.join- def self.match_word_regexp(regexp, engine: :ruby)+ WORD_CHARS = "[\\p{L}\\p{M}\\p{N}\\p{Pc}]"++ def self.match_word_regexp(regexp)s = SPACELESS_SCRIPTS- if engine == :js- leading = "(?:[\\P{L}#{s}]|^|(?=[#{s}]))"- trailing = "(?:(?=[\\P{L}#{s}]|$)|(?<=[#{s}]))"- "#{leading}(#{regexp})#{trailing}"- elsif engine == :ruby- leading = "(?:(?<![[:word:]&&[^#{s}]])|(?=[#{s}]))"- trailing = "(?:(?![[:word:]&&[^#{s}]])|(?<=[#{s}]))"- "#{leading}(#{regexp})#{trailing}"- else- raise "unknown regexp engine: #{engine}"- end+ w = WORD_CHARS+ leading = "(?:(?<!#{w})|(?<=[#{s}])|(?=[#{s}]))"+ trailing = "(?:(?!#{w})|(?=[#{s}])|(?<=[#{s}]))"+ "#{leading}(#{regexp})#{trailing}"endprivate_class_method :match_word_regexpdiff --git a/lib/pretty_text.rb b/lib/pretty_text.rbindex 3fdc93b0551..dc691606f7b 100644--- a/lib/pretty_text.rb+++ b/lib/pretty_text.rb@@ -218,9 +218,9 @@ module PrettyText__optInput.emojiUnicodeReplacer = __emojiUnicodeReplacer;__optInput.emojiDenyList = #{Emoji.denied.to_json};__optInput.lookupUploadUrls = __lookupUploadUrls;- __optInput.censoredRegexp = #{WordWatcher.serialized_regexps_for_action(:censor, engine: :js).to_json};- __optInput.watchedWordsReplace = #{WordWatcher.regexps_for_action(:replace, engine: :js).to_json};- __optInput.watchedWordsLink = #{WordWatcher.regexps_for_action(:link, engine: :js).to_json};+ __optInput.censoredRegexp = #{WordWatcher.serialized_regexps_for_action(:censor).to_json};+ __optInput.watchedWordsReplace = #{WordWatcher.regexps_for_action(:replace).to_json};+ __optInput.watchedWordsLink = #{WordWatcher.regexps_for_action(:link).to_json};__optInput.additionalOptions = #{Site.markdown_additional_options.to_json};__optInput.avatar_sizes = #{SiteSetting.avatar_sizes.to_json};JSdiff --git a/spec/requests/admin/watched_words_controller_spec.rb b/spec/requests/admin/watched_words_controller_spec.rbindex 84fc5a2216e..56a768af9ce 100644--- a/spec/requests/admin/watched_words_controller_spec.rb+++ b/spec/requests/admin/watched_words_controller_spec.rb@@ -38,20 +38,20 @@ RSpec.describe Admin::WatchedWordsController dohash_including("id" => word1.id,"word" => word1.word,- "regexp" => WordWatcher.word_to_regexp(word1.word, engine: :js),+ "regexp" => WordWatcher.word_to_regexp(word1.word),"case_sensitive" => false,"action" => "block",),hash_including("id" => word4.id,"word" => word4.word,- "regexp" => WordWatcher.word_to_regexp(word4.word, engine: :js),+ "regexp" => WordWatcher.word_to_regexp(word4.word),"case_sensitive" => false,"action" => "censor",),)expect(watched_words["compiled_regular_expressions"]["block"].first).to eq(- WordWatcher.serialized_regexps_for_action(:block, engine: :js).first.deep_stringify_keys,+ WordWatcher.serialized_regexps_for_action(:block).first.deep_stringify_keys,)endenddiff --git a/spec/services/word_watcher_spec.rb b/spec/services/word_watcher_spec.rbindex 7ee982e8be2..a2cf184366b 100644--- a/spec/services/word_watcher_spec.rb+++ b/spec/services/word_watcher_spec.rb@@ -1,13 +1,13 @@# frozen_string_literal: trueRSpec.describe WordWatcher do- let(:raw) { <<~RAW.strip }- Do you like liquorice?-+ def matches(text, action = :require_approval)+ described_class.new(text).word_matches_for_action?(action)+ end- I really like them. One could even say that I am *addicted* to liquorice. And if- you can mix it up with some anise, then I'm in heaven ;)- RAW+ def matches_all(text, action = :block)+ described_class.new(text).word_matches_for_action?(action, all_matches: true)+ endafter { Discourse.redis.flushdb }@@ -63,39 +63,42 @@ RSpec.describe WordWatcher doendcontext "when watched_words_regular_expressions = true" do- it "returns the proper regexp" do- SiteSetting.watched_words_regular_expressions = true+ before { SiteSetting.watched_words_regular_expressions = true }++ it "matches words and respects case sensitivity" doregexps = described_class.compiled_regexps_for_action(:block)- expect(regexps).to be_an(Array)- expect(regexps.map(&:inspect)).to contain_exactly(- "/(#{word1})|(#{word2})/i",- "/(#{word3})|(#{word4})/",- )+ case_insensitive = regexps.find(&:casefold?)+ case_sensitive = regexps.find { |r| !r.casefold? }++ expect(case_insensitive).to match(word1)+ expect(case_insensitive).to match(word2)+ expect(case_insensitive).to match(word1.upcase)+ expect(case_sensitive).to match(word3)+ expect(case_sensitive).to match(word4)+ expect(case_sensitive).not_to match(word3.swapcase)endendcontext "when watched_words_regular_expressions = false" do- it "returns the proper regexp" do+ it "groups words by case sensitivity and wraps them with word boundaries" doSiteSetting.watched_words_regular_expressions = falseregexps = described_class.compiled_regexps_for_action(:block)- s = WordWatcher::SPACELESS_SCRIPTS- leading = "(?:(?<![[:word:]&&[^#{s}]])|(?=[#{s}]))"- trailing = "(?:(?![[:word:]&&[^#{s}]])|(?<=[#{s}]))"+ case_sensitive = regexps.find { |r| !r.casefold? }+ case_insensitive = regexps.find(&:casefold?)- expect(regexps).to be_an(Array)- expect(regexps.map(&:inspect)).to contain_exactly(- "/#{leading}(#{word1}|#{word2})#{trailing}/i",- "/#{leading}(#{word3}|#{word4})#{trailing}/",- )+ expect(case_insensitive).to match(word1)+ expect(case_insensitive).to match(word2)+ expect(case_sensitive).to match(word3)+ expect(case_sensitive).to match(word4)++ expect(case_insensitive).not_to match("x#{word1}x")+ expect(case_sensitive).not_to match("x#{word3}x")endit "is empty for an action without watched words" do- regexps = described_class.compiled_regexps_for_action(:censor)-- expect(regexps).to be_an(Array)- expect(regexps).to be_empty+ expect(described_class.compiled_regexps_for_action(:censor)).to be_emptyendend@@ -129,8 +132,6 @@ RSpec.describe WordWatcher doit "works correctly when regular expressions are disabled" doregexps = described_class.compiled_regexps_for_action(:block)- expect(regexps).to be_an(Array)- expect(regexps.size).to eq(1)expect(regexps.first).to match("xyzabc")expect(regexps.first).to match(" abc")expect(regexps.first).to match("testabc")@@ -139,10 +140,7 @@ RSpec.describe WordWatcher doit "skips invalid watched words when regular expression are enabled" doSiteSetting.watched_words_regular_expressions = true-- regexps = described_class.compiled_regexps_for_action(:block)- expect(regexps).to be_an(Array)- expect(regexps).to be_empty+ expect(described_class.compiled_regexps_for_action(:block)).to be_emptyendend@@ -155,29 +153,14 @@ RSpec.describe WordWatcher doFabricate(:watched_word, word: "word", action: WatchedWord.actions[:block])end- it "does not raise an exception and still compiles valid words" do+ it "still matches valid words even with invalid regex present" doexpect { described_class.compiled_regexps_for_action(:block) }.not_to raise_error- regexps = described_class.compiled_regexps_for_action(:block)- expect(regexps).to be_an(Array)- expect(regexps).not_to be_empty- expect(regexps.first.inspect).to match(/bad.*word/i)- end-- it "still detects matches for valid words even with invalid regex present" do- watcher = described_class.new("This is a bad word")- expect(watcher.should_block?).to be_truthy- expect(watcher.word_matches_for_action?(:block, all_matches: true)).to include(- "bad",- "word",- )+ expect(matches_all("This is a bad word")).to include("bad", "word")endit "does not break serialized_regexps_for_action" do- expect {- described_class.serialized_regexps_for_action(:block, engine: :js)- }.not_to raise_error- serialized = described_class.serialized_regexps_for_action(:block, engine: :js)- expect(serialized).to be_an(Array)+ expect { described_class.serialized_regexps_for_action(:block) }.not_to raise_error+ serialized = described_class.serialized_regexps_for_action(:block)expect(serialized).not_to be_emptyendend@@ -185,7 +168,7 @@ RSpec.describe WordWatcher dodescribe "#word_matches_for_action?" doit "is falsey when there are no watched words" do- expect(described_class.new(raw).word_matches_for_action?(:require_approval)).to be_falsey+ expect(matches("nothing to see here")).to be_falseyendcontext "with watched words" do@@ -194,125 +177,78 @@ RSpec.describe WordWatcher doendit "is falsey without a match" do- expect(- described_class.new("No liquorice for me, thanks...").word_matches_for_action?(- :require_approval,- ),- ).to be_falsey+ expect(matches("No liquorice for me, thanks...")).to be_falseyend- it "is returns matched words if there's a match" do- matches = described_class.new(raw).word_matches_for_action?(:require_approval)- expect(matches).to be_truthy- expect(matches[1]).to eq(anise.word)+ it "returns matched word on match" do+ expect(matches("I like anise")[1]).to eq("anise")endit "finds at start of string" do- matches =- described_class.new("#{anise.word} is garbage").word_matches_for_action?(- :require_approval,- )- expect(matches[1]).to eq(anise.word)+ expect(matches("#{anise.word} is garbage")[1]).to eq(anise.word)endit "finds at end of string" do- matches =- described_class.new("who likes #{anise.word}").word_matches_for_action?(:require_approval)- expect(matches[1]).to eq(anise.word)+ expect(matches("who likes #{anise.word}")[1]).to eq(anise.word)endit "finds non-letters in place of letters" doFabricate(:watched_word, word: "co(onut", action: WatchedWord.actions[:require_approval])-- matches =- described_class.new("This co(onut is delicious.").word_matches_for_action?(- :require_approval,- )- expect(matches[1]).to eq("co(onut")+ expect(matches("This co(onut is delicious.")[1]).to eq("co(onut")endit "handles * for wildcards" doFabricate(:watched_word, word: "a**le*", action: WatchedWord.actions[:require_approval])-- matches =- described_class.new("I acknowledge you.").word_matches_for_action?(:require_approval)- expect(matches[1]).to eq("acknowledge")+ expect(matches("I acknowledge you.")[1]).to eq("acknowledge")end- it "handles word boundary" do+ it "matches words at boundaries with punctuation" doFabricate(:watched_word, word: "love", action: WatchedWord.actions[:require_approval])- expect(- described_class.new("I Love, bananas.").word_matches_for_action?(:require_approval)[1],- ).to eq("Love")- expect(- described_class.new("I LOVE; apples.").word_matches_for_action?(:require_approval)[1],- ).to eq("LOVE")- expect(- described_class.new("love: is a thing.").word_matches_for_action?(:require_approval)[1],- ).to eq("love")- expect(- described_class.new("I love. oranges").word_matches_for_action?(:require_approval)[1],- ).to eq("love")- expect(- described_class.new("I :love. pineapples").word_matches_for_action?(:require_approval)[1],- ).to eq("love")- expect(- described_class.new("peace ,love and understanding.").word_matches_for_action?(- :require_approval,- )[- 1- ],- ).to eq("love")++ %w[Love, LOVE; love: love. :love. ,love].each do |token|+ text = "I #{token} things"+ word = token.gsub(/[^a-zA-Z]/, "")+ expect(matches(text)[1]).to eq(word), "expected '#{word}' to match in '#{text}'"+ endend- it "handles CJK characters as word boundaries" do+ it "matches CJK watched words within CJK text" doFabricate(:watched_word, word: "测试", action: WatchedWord.actions[:require_approval])- expect(described_class.new("测试").word_matches_for_action?(:require_approval)[1]).to eq("测试")- expect(- described_class.new("这是一个测试文本").word_matches_for_action?(:require_approval)[1],- ).to eq("测试")- expect(- described_class.new("hello 测试 world").word_matches_for_action?(:require_approval)[1],- ).to eq("测试")- expect(described_class.new("API测试结果").word_matches_for_action?(:require_approval)[1]).to eq(- "测试",- )+ expect(matches("测试")[1]).to eq("测试")+ expect(matches("这是一个测试文本")[1]).to eq("测试")+ expect(matches("hello 测试 world")[1]).to eq("测试")+ expect(matches("API测试结果")[1]).to eq("测试")end- it "handles Latin watched words adjacent to CJK text" do+ it "matches Latin watched words adjacent to CJK text" doFabricate(:watched_word, word: "Test", action: WatchedWord.actions[:require_approval])- expect(- described_class.new("我的Test很好").word_matches_for_action?(:require_approval)[1],- ).to eq("Test")- expect(- described_class.new("Testing").word_matches_for_action?(:require_approval),- ).to be_falsey+ expect(matches("我的Test很好")[1]).to eq("Test")+ expect(matches("Testing")).to be_falseyend- it "handles CJK boundaries with the JS engine" do- Fabricate(:watched_word, word: "测试", action: WatchedWord.actions[:require_approval])+ it "does not match across word boundaries" do+ Fabricate(:watched_word, word: "Test", action: WatchedWord.actions[:require_approval])- regexps = described_class.compiled_regexps_for_action(:require_approval, engine: :js)- expect(regexps.size).to eq(1)+ expect(matches("Test")[1]).to eq("Test")+ expect(matches("Test 123")[1]).to eq("Test")+ expect(matches("123Test")).to be_falsey+ expect(matches("Test123")).to be_falsey- re = regexps.first- expect(re).to match("测试")- expect(re).to match("这是一个测试文本")- expect(re).to match("hello 测试 world")- expect(re).to match("API测试结果")+ Fabricate(:watched_word, word: "test", action: WatchedWord.actions[:require_approval])+ expect(matches("foo_test_bar")).to be_falsey+ expect(matches("_test")).to be_falsey+ expect(matches("test_")).to be_falsey+ expect(matches("foo-test-bar")[1]).to eq("test")end- it "handles Latin words adjacent to CJK text with the JS engine" do- Fabricate(:watched_word, word: "Test", action: WatchedWord.actions[:require_approval])-- regexps = described_class.compiled_regexps_for_action(:require_approval, engine: :js)- expect(regexps.size).to eq(1)+ it "treats numbers as word characters at boundaries" do+ Fabricate(:watched_word, word: "123", action: WatchedWord.actions[:require_approval])- re = regexps.first- expect(re).to match("我的Test很好")- expect(re).not_to match("Testing")+ expect(matches("hello 123 world")[1]).to eq("123")+ expect(matches("abc123")).to be_falsey+ expect(matches("123abc")).to be_falseyendcontext "when there are multiple matches" do@@ -322,19 +258,8 @@ RSpec.describe WordWatcher doFabricate(:watched_word, word: word, action: WatchedWord.actions[:block])end- matches =- described_class.new("I hate bananas").word_matches_for_action?(- :block,- all_matches: true,- )- expect(matches).to contain_exactly("hate", "bananas")-- matches =- described_class.new("She hates bananas too").word_matches_for_action?(- :block,- all_matches: true,- )- expect(matches).to contain_exactly("hates", "bananas")+ expect(matches_all("I hate bananas")).to contain_exactly("hate", "bananas")+ expect(matches_all("She hates bananas too")).to contain_exactly("hates", "bananas")endend@@ -349,18 +274,11 @@ RSpec.describe WordWatcher doaction: WatchedWord.actions[:block],)- matches =- described_class.new("pine pineapples apples").word_matches_for_action?(- :block,- all_matches: true,- )- expect(matches).to contain_exactly("pineapples", "apples")-- matches =- described_class.new(- "go watched watch ed ing move d moveed moved moving",- ).word_matches_for_action?(:block, all_matches: true)- expect(matches).to contain_exactly(*%w[watched watch move moved])+ expect(matches_all("pine pineapples apples")).to contain_exactly("pineapples", "apples")++ expect(+ matches_all("go watched watch ed ing move d moveed moved moving"),+ ).to contain_exactly(*%w[watched watch move moved])endendend@@ -368,20 +286,12 @@ RSpec.describe WordWatcher docontext "when word is an emoji" doit "handles emoji" doFabricate(:watched_word, word: ":joy:", action: WatchedWord.actions[:require_approval])-- matches =- described_class.new("Lots of emojis here :joy:").word_matches_for_action?(- :require_approval,- )- expect(matches[1]).to eq(":joy:")+ expect(matches("Lots of emojis here :joy:")[1]).to eq(":joy:")endit "handles unicode emoji" doFabricate(:watched_word, word: "🎃", action: WatchedWord.actions[:require_approval])-- matches =- described_class.new("Halloween party! 🎃").word_matches_for_action?(:require_approval)- expect(matches[1]).to eq("🎃")+ expect(matches("Halloween party! 🎃")[1]).to eq("🎃")endit "handles emoji skin tone" do@@ -390,12 +300,7 @@ RSpec.describe WordWatcher doword: ":woman:t5:",action: WatchedWord.actions[:require_approval],)-- matches =- described_class.new("To Infinity and beyond! 🚀 :woman:t5:").word_matches_for_action?(- :require_approval,- )- expect(matches[1]).to eq(":woman:t5:")+ expect(matches("To Infinity and beyond! 🚀 :woman:t5:")[1]).to eq(":woman:t5:")endend@@ -404,9 +309,7 @@ RSpec.describe WordWatcher doit "supports regular expressions on word boundaries" doFabricate(:watched_word, word: /\btest\b/, action: WatchedWord.actions[:block])-- matches = described_class.new("this is not a test.").word_matches_for_action?(:block)- expect(matches[0]).to eq("test")+ expect(matches("this is not a test.", :block)[0]).to eq("test")endit "supports regular expressions as a site setting" do@@ -416,31 +319,17 @@ RSpec.describe WordWatcher doaction: WatchedWord.actions[:require_approval],)- matches =- described_class.new("Evil Trout is cool").word_matches_for_action?(:require_approval)- expect(matches[0]).to eq("Trout")-- matches =- described_class.new("Evil Troot is cool").word_matches_for_action?(:require_approval)- expect(matches[0]).to eq("Troot")-- matches = described_class.new("trooooooooot").word_matches_for_action?(:require_approval)- expect(matches[0]).to eq("trooooooooot")+ expect(matches("Evil Trout is cool")[0]).to eq("Trout")+ expect(matches("Evil Troot is cool")[0]).to eq("Troot")+ expect(matches("trooooooooot")[0]).to eq("trooooooooot")endit "support uppercase" doFabricate(:watched_word, word: /a\S+ce/, action: WatchedWord.actions[:require_approval])- matches = described_class.new("Amazing place").word_matches_for_action?(:require_approval)- expect(matches).to be_nil-- matches =- described_class.new("Amazing applesauce").word_matches_for_action?(:require_approval)- expect(matches[0]).to eq("applesauce")-- matches =- described_class.new("Amazing AppleSauce").word_matches_for_action?(:require_approval)- expect(matches[0]).to eq("AppleSauce")+ expect(matches("Amazing place")).to be_nil+ expect(matches("Amazing applesauce")[0]).to eq("applesauce")+ expect(matches("Amazing AppleSauce")[0]).to eq("AppleSauce")endend@@ -459,11 +348,9 @@ RSpec.describe WordWatcher doSiteSetting.watched_words_regular_expressions = trueFabricate(:watched_word, word: "p(rivate|ublic)", action: WatchedWord.actions[:block])- matches =- described_class.new(- "PUBLIC: Discourse is great for public discourse",- ).word_matches_for_action?(:block, all_matches: true)- expect(matches).to contain_exactly("PUBLIC", "Discourse", "public")+ expect(+ matches_all("PUBLIC: Discourse is great for public discourse"),+ ).to contain_exactly("PUBLIC", "Discourse", "public")endend@@ -472,12 +359,9 @@ RSpec.describe WordWatcher doSiteSetting.watched_words_regular_expressions = falseFabricate(:watched_word, word: "private", action: WatchedWord.actions[:block])- matches =- described_class.new(- "PRIVATE: Discourse is also great private discourse",- ).word_matches_for_action?(:block, all_matches: true)-- expect(matches).to contain_exactly("PRIVATE", "Discourse", "private")+ expect(+ matches_all("PRIVATE: Discourse is also great private discourse"),+ ).to contain_exactly("PRIVATE", "Discourse", "private")endendend