fix(core): free text's detector reads a dot, a longer run, a line break and invisible characters, and a reference takes nine digits

A dot joins an SSN's groups only when it joins both (000.00.0000), never an
EIN's: a coordinate such as 47.6062095 is a number, not a tax id. A group
that starts or ends inside a longer run of digits and dashes (a date's day
then its reference, a part number) belongs to that run. A line break reads
as a space and zero-width and soft-hyphen characters are not counted, as the
strict party reading already has it. The reading is one detector with a
parameter: a reference (tag, serial, invoice or payment reference, account
code, label, where a W-9 or W-4 is kept) drops the bare-nine group, since a
serial or a check number is nine digits. The engine now also refuses a
payment's reference (printed shapes) and a discount's reason (free text),
which only the tools' table covered; a payment entry's description, free
text, shows the reference masked. A project's field has an engine-level test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 16:12:59 -07:00
1 parent 657daf43da
commit dd5f1befd6
8 files changed
+604 -78

No files matched your search

+19 -5
View File
@@ -416,7 +416,7 @@ fn tin_separator(c: char) -> bool {
/// right-to-left marks and the other directional formatting characters,
/// the word joiner, the byte-order mark, the variation selectors, the tags
/// and the fillers. None is ASCII.
fn tin_invisible(c: char) -> bool {
pub(crate) fn tin_invisible(c: char) -> bool {
matches!(
c,
'\u{AD}'
@@ -720,10 +720,22 @@ pub fn check_text(field: &str, text: &str) -> Result<(), String> {
/// Check a free text field: no tax id's shape (a nine-digit number standing
/// alone, an SSN's 3-2-4, an EIN's 2-7: [`crate::settings::check_free_text`]),
/// at most 500 characters, no control characters except newline. For a
/// memo, a note, a reason or a reference; a party's own fields keep the
/// strict [`check_text`] (BS-partner-2; the owner's choice, 2026-11-21).
/// memo, a note or a reason; a party's own fields keep the strict
/// [`check_text`] (BS-partner-2; the owner's choice, 2026-11-21).
pub fn check_note(field: &str, text: &str) -> Result<(), String> {
crate::settings::check_free_text(field, text)?;
check_note_form(field, text)
}
/// [`check_note`] for a reference (a payment's or a send's reference, a
/// file's location): only the grouped shapes are refused, a bare nine
/// digits is allowed ([`crate::settings::check_reference_text`]).
pub fn check_reference_note(field: &str, text: &str) -> Result<(), String> {
crate::settings::check_reference_text(field, text)?;
check_note_form(field, text)
}
fn check_note_form(field: &str, text: &str) -> Result<(), String> {
if text.chars().count() > 500 {
return Err(format!("{field} is at most 500 characters"));
}
@@ -762,12 +774,14 @@ impl W9Facts {
("entity_type", Some(self.entity_type.as_str())),
("exempt_payee_code", self.exempt_payee_code.as_deref()),
("fatca_code", self.fatca_code.as_deref()),
("kept_at", Some(self.kept_at.as_str())),
] {
if let Some(t) = t {
check_text(f, t)?;
}
}
// Where the paper is kept is a reference (a binder, a portal, a
// file name): a bare nine digits is allowed (WB-partner-15).
check_reference_note("kept_at", &self.kept_at)?;
if let Some(h) = &self.vault_record
&& (h.len() != 64 || !h.chars().all(|c| c.is_ascii_hexdigit()))
{
@@ -786,7 +800,7 @@ impl W4Facts {
if self.kept_at.trim().is_empty() {
return Err("say where the W-4 itself is kept".into());
}
check_text("kept_at", &self.kept_at)
check_reference_note("kept_at", &self.kept_at)
}
}