If you test the phrase 'Hello hello hello hello hello hello', only ever other word is matched.

Comments

q0rban’s picture

Title: Standalone doesn't account for word repition » Standalone doesn't account for word repitition
q0rban’s picture

Title: Standalone doesn't account for word repitition » Standalone doesn't account for word repetition

Sheesh.

dunx’s picture

Same with 6-1.1. Should I raise a new issue?

yngens’s picture

same issue here with 6.x-1.x-dev. subscribe.

csavio’s picture

I believe the problem is the $word->standalone pattern in the wordfilter_filter_process function. I think you could use word boundaries (\b) instead of trying to back-reference negated characters (\W) and it seems to work much better.

if ($word->standalone) {
  $pattern = '/\b'. preg_quote($word->words, '/') .'\b/i';
}

Then your replacements become simpler as well

if (!preg_match('/^</', $part)) {
  $new_string .= preg_replace($pattern, $replacement, $part);
}
$text = preg_replace($pattern, $replacement, $text);

Unless I'm missing something this seems to resolve the problem for me.

q0rban’s picture

Status: Active » Closed (duplicate)

I'm closing this in favor of #883940: Standalone doesn't count for first/last word of sentence or word repetition. I know, I'm the one that created this issue, but the patch there resolves both, so I'm going to retitle it.