feat(classifier): has_short_latin_name() helper for drop-logic

This commit is contained in:
Vladimir Bryzgalov
2026-04-21 16:01:58 +05:00
parent b5c939e9e4
commit 660a0d2b7c
2 changed files with 57 additions and 0 deletions
+19
View File
@@ -243,4 +243,23 @@ final class Classifier
}
return false;
}
/**
* Checks whether the form's name field contains 1-3 ASCII alphanumeric characters
* (typical bot pattern: "OB", "MU", "A1B"). Used by drop hard-rule.
*
* Looks first at canonical CF7 keys (your-name, name, имя, fio), then falls back to
* the value-based heuristic in FieldDetector::find_name(). Returns false if no name
* field is present (i.e. forms without a name field are immune to this rule).
*
* @param array<string,string|string[]> $fields CF7 posted_data
*/
public static function has_short_latin_name(array $fields): bool
{
$name = self::pick_field($fields, ['your-name', 'name', 'имя', 'fio']);
if ($name === '') $name = FieldDetector::find_name($fields);
$name = trim($name);
if ($name === '') return false;
return (bool)preg_match('/^[A-Za-z0-9]{1,3}$/', $name);
}
}