Files
Ruslan KonviserandClaude Opus 5 d46b0d511c refactor(docs): one canonicalization, imported by both the audit gate and the CI corpus suite
The legacy rich-text audit re-implemented the canonicalization that already lived inside
'legacy-html-corpus.spec.ts'. The author's reason was sound — importing a Jest spec would
execute describe() outside a runner — but the duplication meant the audit GATE and the CI
regression SUITE could silently disagree about what counts as "loss", which is the exact
question both exist to answer. (SonarCloud also measured it: 71 duplicated lines, 6.97% of
that file, pushing the PR to 3.2% against a 3% gate.)

Both now import 'legacy-html-canonical.util.ts'. Net 312 deletions / 18 insertions.

Comparing the two copies surfaced four differences, all resolved without changing
behaviour: the spec's bare .sort() vs the audit's explicit code-unit comparator (identical
semantics — the default sort IS UTF-16 code-unit order — so the explicit, self-documenting
one was kept); string-returning 'canonicalize' vs the audit's HTMLElement-returning
'canonicalBody' + 'serializeBody' (both kept, the former composed from the latter, so each
caller keeps the exact call it had); drifted comments on the anchor step (merged); and
prettier wrapping.

It also surfaced a latent hazard both copies shared, now fixed: attribute NAMES were sorted
with localeCompare, which quietly contradicted the code-unit rule stated a few lines above.
ICU collation is locale- and version-dependent, so two machines could order colspan/data-x/
href differently and manufacture a "loss" that is only a different attribute order — in the
one routine whose entire job is deciding whether two HTML strings are equivalent. Safe to
change because canonicalization is applied to BOTH sides of every comparison, so a
reordering shifts them identically; confirmed by the suites below rather than by argument.

Verified after the change: corpus suite 43/43, audit --self-test 6/6 (exit 0), 'tsc -p
tools/tsconfig.audit.json' clean, 'nx build ui-core' green, cspell clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-09 16:55:54 +02:00
..
2024-12-20 08:30:49 +01:00