Skip to content

Commit 8ef3d1e

Browse files
committed
Ajustes no regex do getSpamTerms Ref.: #1
1 parent 6f0d841 commit 8ef3d1e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Plugin.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function formatText($text)
259259
$text = trim($text);
260260
$text = strip_tags($text);
261261
$text = mb_strtolower($text);
262-
$text = preg_replace("/[^a-z0-9_\s]/", "", $text);
262+
$text = preg_replace("/[^a-z0-9 \s]/", "", $text);
263263

264264
return $text;
265265
}
@@ -295,19 +295,24 @@ public function getSpamTerms($entity, $terms): array {
295295
$fields = $this->config['fields'];
296296
$spam_detector = [];
297297
$found_terms = [];
298-
298+
$special_chars = ['@', '#', '$', '%', '^', '·', '&', '*', '(', ')', '-', '_', '=', '+', '{', '}', '[', ']', '|', ':', ';', '"', '\'', '<', '>', ',', '.', '?', '/', ' ', ''];
299+
299300
foreach ($fields as $field) {
300301
if ($value = $entity->$field) {
301302
$lowercase_value = $this->formatText($value);
302303

303304
foreach ($terms as $term) {
304305
$lowercase_term = $this->formatText($term);
306+
307+
foreach($special_chars as $special_char) {
308+
$_term = implode($special_char, mb_str_split($lowercase_term));
305309

306-
$pattern = '/\b' . preg_quote($lowercase_term, '/') . '\b/';
307-
308-
if (preg_match($pattern, $lowercase_value) && !in_array($term, $found_terms)) {
309-
310-
$found_terms[$field][] = $term;
310+
$pattern = '/([^\w]|[_0-9]|^)' . preg_quote($_term, '/') . '([^\w]|[_0-9]|$)/';
311+
312+
if (preg_match($pattern, $lowercase_value) && !in_array($term, $found_terms)) {
313+
314+
$found_terms[$field][] = $term;
315+
}
311316
}
312317
}
313318
}

0 commit comments

Comments
 (0)