Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ Changes up to v0.1.0 are in the git history.

## Unreleased

**Intent:** a map whose commit sha was all digits with a leading zero, such
as `0179008`, was read as `179008`, so the comment named a commit that does
not exist.

**Change:** `src/vendor/complexmd.js` is copied again from complex-md main,
which keeps an unquoted all-digit `commit` exactly as written. A test in
`test/map.test.js` pins it.

**Intent:** the bounds job ran complex-md 0.10.0 after 0.11.0 was on npm
(published 2026-10-25), and `verify: true` warned and checked nothing,
because 0.10.0 has no verify command
Expand Down
70 changes: 62 additions & 8 deletions src/vendor/complexmd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Vendored from complex-md (MIT, https://github.com/KletoWorks/complex-md),
// cli/src/complexmd.js at commit 5bc6f06f6fce9a83dbf950b1d1fa3c4df5a43523,
// cli/src/complexmd.js at commit 59c10fe37573b11302b964b7a0273725b83dec46,
// unchanged below this header. The action reads COMPLEX.md with the same
// parser the CLI uses, so a map that the CLI reads, the action reads too.
// Update it by copying the file again and running npm test.
Expand All @@ -21,13 +21,29 @@ export function parseComplexMd(text) {
const m = /^---\n([\s\S]*?)\n---\n?([\s\S]*)$/.exec(text);
if (!m) return null;
const fm = parseFrontMatter(m[1]);
if (!Object.hasOwn(fm, 'complex_md')) return null;
if (fm.complex_md === '0.3' && !Object.hasOwn(fm, 'generator') && typeof fm.tool === 'string') {
const slash = fm.tool.indexOf('/');
fm.generator = slash < 0
? { name: fm.tool }
: { name: fm.tool.slice(0, slash), version: fm.tool.slice(slash + 1) };
delete fm.tool;
}
/* A commit sha is a string even when every character is a digit. The
scalar reader turns an all digit value into a Number, and a map whose
sha happened to be 1234567 then failed every string comparison against
HEAD and reported itself stale. A few percent of shas are all digits,
which is exactly the rate at which a test with unpinned commit dates
fails in CI and passes on the machine that wrote it. */
if (fm.commit !== undefined && fm.commit !== null) fm.commit = String(fm.commit);
fails in CI and passes on the machine that wrote it. String() of that
Number also drops a leading zero: 0179008 came back as 179008, which
resolves to no commit, so a note called the map's commit not in the
history. frontMatter in generate.js writes the sha unquoted, so an all
digit value is taken as written. parseFrontMatter keeps the Number,
because lint reports the commit as written. */
if (fm.commit !== undefined && fm.commit !== null) {
const raw = /^commit:[ \t]*(\d+)[ \t]*$/m.exec(m[1])?.[1];
fm.commit = typeof fm.commit === 'number' && raw ? raw : String(fm.commit);
}
const prose = m[2];
const sections = splitSections(prose);
const hotspotParas = paragraphs(sections['Why these files are hot'] || '');
Expand Down Expand Up @@ -178,20 +194,58 @@ export function parseFrontMatter(src) {
let i = 0;
const scalar = (v) => {
v = v.trim();
if (/^".*"$/.test(v) || /^'.*'$/.test(v)) return v.slice(1, -1);
/* frontMatter quotes with JSON.stringify, so a double quoted value is
read back with JSON.parse: \" becomes " and \\ becomes \. An escape
JSON lacks (YAML's \x41) keeps its backslash, and only \" and \\ are
undone. A single quoted value doubles its quote, as YAML does. */
if (/^".*"$/.test(v)) {
try {
return JSON.parse(v);
} catch {
return v.slice(1, -1).replace(/\\(["\\])/g, '$1');
}
}
if (/^'.*'$/.test(v)) return v.slice(1, -1).replace(/''/g, "'");
if (/^-?\d+(\.\d+)?$/.test(v)) return Number(v);
/* An inline flow sequence. A generated map never writes one: every list
it emits is a block. A HAND WRITTEN map does, and writing one by hand
is a documented way to use this format, so `co_change: []` arriving as
the two character string "[]" is a real defect and not a theoretical
one. It crashed `wire` on the first end to end run of 0.7.0. */
if (/^\[.*\]$/.test(v)) {
const inner = v.slice(1, -1).trim();
if (!inner) return [];
return inner.split(',').map((x) => scalar(x));
return flowList(v.slice(1, -1));
}
return v;
};
/* A comma inside a double quoted item does not split it. Only a quote
that opens an item starts a quoted scalar: spec 0.4 section 6.2 lets a
plain scalar hold a quote after its first character, and frontMatter
writes co_change paths unquoted, so lib/a"b.js is a plain path. */
const flowList = (inner) => {
if (!inner.trim()) return [];
const items = [];
let quoted = false;
let escaped = false;
let opening = true;
let start = 0;
for (let j = 0; j < inner.length; j++) {
const c = inner[j];
if (quoted) {
if (escaped) escaped = false;
else if (c === '\\') escaped = true;
else if (c === '"') quoted = false;
} else if (c === ',') {
items.push(scalar(inner.slice(start, j)));
start = j + 1;
opening = true;
} else if (opening && c === '"') {
quoted = true;
opening = false;
} else if (c !== ' ') opening = false;
}
items.push(scalar(inner.slice(start)));
return items;
};
while (i < lines.length) {
const line = lines[i];
const kv = /^([A-Za-z_][\w]*):\s*(.*)$/.exec(line);
Expand Down Expand Up @@ -238,7 +292,7 @@ export function parseFrontMatter(src) {
function value(v) {
v = v.trim();
const arr = /^\[(.*)\]$/.exec(v);
if (arr) return arr[1].split(',').map((s) => scalar(s));
if (arr) return flowList(arr[1]);
return scalar(v);
}
}
6 changes: 6 additions & 0 deletions test/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ test('the vendored parser reads a real generated map', () => {
test('a file without front matter parses to null', () => {
assert.equal(parseComplexMd('# not a map\n'), null);
});

test('an unquoted all-digit commit keeps its leading zero', async () => {
const { parseComplexMd } = await import('../src/vendor/complexmd.js');
const text = '---\ncomplex_md: "0.3"\ncommit: 0179008\nhotspots:\nco_change:\n---\n\n## Where the risk lives\n\nx\n';
assert.equal(parseComplexMd(text).front.commit, '0179008');
});
Loading