fix: phone leak, field-by-value detection, strict Flamingo email fallback
Three pilot-surfaced issues in one pass: 1. PhoneParser regex used '\s' in the candidate character class, so a digit on a following flattened line bled into the phone. '+7977 6277470\n1' (phone + trailing checkbox value) parsed as 12 digits, producing '+797762774701'. Replaced '\s' with a literal space so newlines/tabs stop the candidate. 2. Custom-themed forms don't use 'your-name' / 'your-email' keys (washanyanya.ru has text-211 / text-212 / name_user). Added FieldDetector::find_name + find_email as fallbacks. Classifier and MessageFormatter now call them if no standard key matches, so 'Александр' in text-211 is recognised as a cyrillic name and scored / displayed accordingly. 3. FlamingoHelper copied '_from_email' into 'your-email' without validating it. Flamingo derives that meta from whatever field it considers "first"; on phone-first forms it ends up holding the phone number. Now we only copy _from_email if it contains '@', and dropped the _from_name shortcut entirely — FieldDetector handles the name via the actual field values. Tests: +1 FieldDetectorTest (13 cases); +2 PhoneParserTest cases for newline/tab bleeds; +1 ClassifierTest case; +1 MessageFormatterTest case for custom field keys. Full suite 53/53 green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -151,4 +151,31 @@ final class MessageFormatterTest extends TestCase
|
||||
|
||||
self::assertStringContainsString('🟡 неясно', $r['text']);
|
||||
}
|
||||
|
||||
public function test_custom_form_field_keys_are_detected(): void
|
||||
{
|
||||
// washanyanya.ru-style form — fields are named text-NNN, name_user,
|
||||
// etc. We must still pull out name + phone via value heuristics.
|
||||
$fields = [
|
||||
'text-211' => 'Александр',
|
||||
'text-212' => '+79776277470',
|
||||
'checkbox-382' => '1',
|
||||
];
|
||||
$classification = Classifier::classify($fields, ['reason' => 'Akismet']);
|
||||
$r = MessageFormatter::build([
|
||||
'fields' => $fields, 'classification' => $classification,
|
||||
'site_title' => 's.ru', 'form_title' => 'f',
|
||||
'submitted_at' => '18.04.2026', 'reason' => 'Akismet',
|
||||
'ip' => '', 'user_agent' => '', 'is_retro' => false,
|
||||
]);
|
||||
|
||||
// Name resolves to 'Александр' via FieldDetector
|
||||
self::assertStringContainsString('Александр', $r['text']);
|
||||
// Phone correctly parsed (11 digits, no trailing checkbox '1')
|
||||
self::assertStringContainsString('+7 (977) 627-74-70', $r['text']);
|
||||
// Email stays empty (no @-like value)
|
||||
self::assertStringContainsString("📧 (не указан)", $r['text']);
|
||||
// The checkbox value should still appear in 'Прочие поля'
|
||||
self::assertStringContainsString('checkbox-382: 1', $r['text']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user