Anders429 / word_filter

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

Alias after Separator no longer traversed #3

Closed Anders429 closed 3 years ago

Anders429 commented 3 years ago

It appears that, with the 0.1.4 release, aliases after separators no longer are traversed in matching.

Example:

use word_filter::{Options, WordFilter};

let filter = WordFilter::new(
    &["bar"],
    &[],
    &[" "],
    &[("a", "A")],
    Options::default(),
);

assert_eq!(filter.find("b Ar"), vec!["bar"].into_boxed_slice());

This is a regression, as it was working in 0.1.3. Some work was done to refactor finding pointers, specifically with finding aliases, so that may be a place to look.

For now, I will yank 0.1.4.

Anders429 commented 3 years ago

The issue is with this line. It defines a HashSet inline, which unfortunately doesn't define a new set every time, but instead defines one set that is repeatedly used. Therefore, since the set is filled with addresses of already-visited nodes, trying to find alias nodes after passing through a separator means every single alias will have already been visited on the previous iteration.

The solution is to define a new HashSet on every iteration.

Anders429 commented 3 years ago

Fixed with this commit.