Anders429 / word_filter

A Word Filter for filtering text.
Apache License 2.0
1 stars 0 forks source link

Separators at end of matches #1

Closed Anders429 closed 3 years ago

Anders429 commented 3 years ago

It appears that separators are not included at the beginning of matches, but are included at the end. This causes examples like the following to fail:

use word_filter::{Options, WordFilter};

let word_filter = WordFilter::new(&["foo"], &[], &[" "], &[], Options::default());

assert_eq!(word_filter.censor("bar foo bar"), "bar *** bar");

The assertion doesn't pass, because the censor returns "bar ****bar", which is not what we want. Separators shouldn't be included when they are at either end of the match.

Anders429 commented 3 years ago

This is fixed by keeping track of whether a Pointer is within a separator's graph. If it is, then matches and exceptions found on returning are not stored, since it is assumed they were already encountered prior to entering the separator's graph.

Relevant commit is here.