fix(filters): honour whole_word
The whole_word field was stored and returned by the API, but the regex always used word boundaries. As in Mastodon, a filter with whole_word false now also matches inside words.
This commit is contained in:
parent
f975db8719
commit
422a1d1475
3 changed files with 19 additions and 4 deletions
|
|
@ -233,6 +233,17 @@ defmodule Pleroma.FilterTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "matches inside words when whole_word is false" do
|
||||
filters = [%Filter{phrase: "cat", whole_word: false}, %Filter{phrase: "dog"}]
|
||||
pg = Filter.compose_regex(filters)
|
||||
re = Filter.compose_regex(filters, :re)
|
||||
|
||||
for {text, expected} <- [{"a catalog", true}, {"a hotdog", false}, {"a dog", true}] do
|
||||
assert pg_match?(pg, text) == expected
|
||||
assert Regex.match?(re, text) == expected
|
||||
end
|
||||
end
|
||||
|
||||
test "keeps word boundaries for every phrase in Elixir" do
|
||||
regex = Filter.compose_regex(filters(["cat", "dog"]), :re)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue