fix(scripts): keep a frontmatter field whose value ends in a line terminator - #1208
Conversation
There was a problem hiding this comment.
Correct. Without the m flag $ anchors at end of input only, so ([\s\S]*)$ matches greedily to the end and cannot backtrack, and trim() already strips CR/U+2028/U+2029 from the captured value, so the field comes out clean.
Checked the one case that would worry me, a value that swallows a following key: with CR-only line endings the whole block collapses to a single "line" and title:a\rdescription:b now yields a title of a\rdescription:b where before both fields vanished. It still fails validation, because description never lands in the map, so this cannot turn into a false pass. And it is unreachable regardless since FRONTMATTER requires \r?\n delimiters.
Nit, no action needed here: there is no test harness under scripts/, so the fuzzing evidence lives only in the PR body. If one ever gets added, title:a + CR is the case to pin.
Closes #1207. Follow-up to #1206, from the nit on its review, which merged before this could land on it.
#1206 claimed its rewrite changed nothing. That held for the alphabet I fuzzed, which had no line terminator in it.
.excludes CR, U+2028 and U+2029 while\sincludes them, so a value ending in one stopped matching and the field vanished:title:a+ CR went fromato "frontmatter needs a non-empty title".Measured on 400,000 random lines, this time with CR, U+2028 and U+2029 in the alphabet:
(.*), as merged([\s\S]*), this PRSo
[\s\S]*never loses a field the original kept. It differs only where a terminator sits inside the value, and there the original's behaviour was an accident of what.matches rather than a rule:title: a+ U+2028 +bhas a title, and reporting it as missing was a false failure.Still linear: without the
mflag$only matches at the end, so the greedy[\s\S]*runs straight there and never backtracks. 0.0 ms at 20,000 characters.Not reachable through the normal path either way, since the block is split on
\r?\nfirst.node scripts/validate-site-docs.mjs: 169 pages validated.