fix(server): plan 4 — RULE12 paren-count scanner ignores string literals

The entity generator's RULE12_fixGarbledCheckExpressions CHECK-expression
paren-balance scanner counted every `(`/`)` character regardless of
whether it fell inside a single-quoted SQL string literal. A CHECK
expression like `status IN ('confirmed)', 'tentative')` has a literal `)`
inside its first string value; the scanner would hit depth 0 at that
in-string character and truncate the expression, losing its own real
closing paren. The scanner now tracks single-quote string state (handling
the doubled `''` SQLite escape) and skips parens while inside one.

Latent-bug fix — no shipped entity's CHECK expression has hit this shape
yet (3d's ledger: "nothing affected today").
This commit is contained in:
jubnl
2026-09-24 06:05:14 +02:00
parent ea7b93de5d
commit 7f61d69add
2 changed files with 42 additions and 2 deletions
@@ -549,6 +549,18 @@ describe('RULE12_fixGarbledCheckExpressions', () => {
const fixups = RULE12_fixGarbledCheckExpressions([meta]);
expect(fixups).toEqual([]);
});
it("RULE12-007: a quoted ')' inside a CHECK expression's own string literal is not mistaken for a closing paren — left byte-identical, no fixup", () => {
const meta = fixtureMeta('SchoolHolidayPeriods', 'school_holiday_periods', []);
// The IN-list's first value itself contains a literal ')'. A naive
// char-by-char paren count would hit depth 0 at that in-string
// character and truncate the expression, losing the list's own real
// closing paren — this fixture pins that it does not.
meta.checks = [{ name: 'sh_status_check', expression: "status IN ('confirmed)', 'tentative')" }];
const fixups = RULE12_fixGarbledCheckExpressions([meta]);
expect(meta.checks[0].expression).toBe("status IN ('confirmed)', 'tentative')");
expect(fixups).toEqual([]);
});
});
describe('RULE13_pinDeleteRuleDrift', () => {