fix(llm): word-boundary INN match, tighten edge cases (#1640 follow-up) #1703

Merged
lekss361 merged 1 commit from fix/inn-regex-word-boundary-1682 into main 2026-06-17 18:34:53 +00:00
Owner

Проблема (ревью #1682)

Lookarounds (?<!\d)...(?!\d) блокировали только соседние цифры → ИНН ref7707083893 (alpha-префикс) и ИНН 7707083893more (alpha-суффикс) всё ещё матчились.

Решение

(?<!\d)(?<!\w), (?!\d)(?!\w) — блокирует любой word-char (буква/цифра/underscore). \b не подходит (между буквой и цифрой границы \b нет). Контекст-якорь + checksum из #1640 без изменений.

Verify

ruff clean; pytest (redact/inn/pii) → 53 passed (+6 boundary-кейсов).

## Проблема (ревью #1682) Lookarounds `(?<!\d)...(?!\d)` блокировали только соседние цифры → `ИНН ref7707083893` (alpha-префикс) и `ИНН 7707083893more` (alpha-суффикс) всё ещё матчились. ## Решение `(?<!\d)`→`(?<!\w)`, `(?!\d)`→`(?!\w)` — блокирует любой word-char (буква/цифра/underscore). `\b` не подходит (между буквой и цифрой границы `\b` нет). Контекст-якорь + checksum из #1640 без изменений. ## Verify `ruff` clean; `pytest` (redact/inn/pii) → **53 passed** (+6 boundary-кейсов).
lekss361 added 1 commit 2026-06-17 18:28:41 +00:00
fix(llm): word-boundary INN match, tighten edge cases (#1640 follow-up)
Some checks failed
CI / backend-tests (push) Has been cancelled
CI / frontend-tests (push) Has been cancelled
CI / openapi-codegen-check (push) Has been cancelled
CI / changes (push) Has been cancelled
CI / changes (pull_request) Has been cancelled
CI / backend-tests (pull_request) Has been cancelled
CI / frontend-tests (pull_request) Has been cancelled
CI / openapi-codegen-check (pull_request) Has been cancelled
4309a12c67
Replace (?<!\d)/(?!\d) lookarounds on the digit block in _INN_RE with
(?<!\w)/(?!\w). The old (?<!\d) did not block alpha-prefixed tokens
(e.g. «ИНН ref7707083893»), and (?!\d) did not block alpha-suffixed
tokens (e.g. «ИНН 7707083893more»). \b is unsuitable here because
Python \w covers both letters and digits, so there is no \b boundary
between an alpha char and a digit char. The (?<!\w)/(?!\w) pair
correctly anchors the 10/12-digit INN block to non-word boundaries on
both sides. Context anchor and checksum gate from #1640 are unchanged.

Adds 6 regression tests covering: alpha-prefix, alpha-suffix,
embedded mid-token, 12-digit alpha-prefix, punctuation separator
(should match), and end-of-string (should match).
lekss361 merged commit 6bf1042171 into main 2026-06-17 18:34:53 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lekss361/gendesign#1703
No description provided.