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
35 changes: 35 additions & 0 deletions .github/scripts/pr-issue-linkage.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,41 @@ test("HTML-comment syntax in a fenced code block does not hide later linkage met
assert.equal(failedWith, null);
});

test("linkage markers inside an inline code span do not satisfy the gate", () => {
const failedWith = runScript(
"Example: `No linked issue`\n\n## Related\n\n- #123",
);
assert.ok(
failedWith,
"inline-code linkage text must not count as rendered metadata",
);
assert.match(failedWith, /closing keyword/);
});

test("linkage markers inside a fenced code block do not satisfy the gate", () => {
const failedWith = runScript(
"```md\nNo linked issue\n\n## Related\n\n- #123\n```",
);
assert.ok(
failedWith,
"fenced linkage text must not count as rendered metadata",
);
assert.match(failedWith, /Related/);
assert.match(failedWith, /closing keyword/);
});

test("linkage markers inside an indented code block do not satisfy the gate", () => {
const failedWith = runScript(
" No linked issue\n\n ## Related\n\n - #123",
);
assert.ok(
failedWith,
"indented linkage text must not count as rendered metadata",
);
assert.match(failedWith, /Related/);
assert.match(failedWith, /closing keyword/);
});

test("an unmatched backtick does not expose linkage metadata hidden in a later HTML comment", () => {
const failedWith = runScript(
"A stray ` delimiter.\n\n<!-- Closes #1 -->\n\n## Related\n\nn/a",
Expand Down
20 changes: 14 additions & 6 deletions .github/workflows/pr-issue-linkage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ jobs:
// parser and rendered Markdown both ignore commented-out text, and a PR template
// ships its instructional prose inside comments. Comment-looking text inside an
// inline code span or fenced code block is rendered literally, though, so it must
// not open a comment and hide valid metadata later in the body.
// not open a comment and hide valid metadata later in the body. Code contents are
// masked from the returned text so example linkage markers cannot satisfy the gate.
const rawBody = process.env.PR_BODY || "";

function stripRenderedHtmlComments(text) {
Expand Down Expand Up @@ -149,7 +150,7 @@ jobs:
if (!commentOpen && inlineTicks === null) {
const marker = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);
if (fence !== null) {
output.push(line);
output.push("");
if (
marker !== null &&
marker[1][0] === fence.char &&
Expand All @@ -165,7 +166,11 @@ jobs:
!(marker[1][0] === "`" && marker[2].includes("`"))
) {
fence = { char: marker[1][0], length: marker[1].length };
output.push(line);
output.push("");
continue;
}
if (/^(?: {4}|\t)/.test(line)) {
output.push("");
continue;
}
}
Expand All @@ -187,14 +192,17 @@ jobs:
let end = index + 1;
while (line[end] === "`") end += 1;
const ticks = end - index;
const wasInline = inlineTicks !== null;
if (
inlineTicks === null &&
!wasInline &&
hasClosingTickRun(lineIndex, end, ticks)
) {
inlineTicks = ticks;
}
else if (inlineTicks === ticks) inlineTicks = null;
rendered += line.slice(index, end);
if (!wasInline && inlineTicks === null) {
rendered += line.slice(index, end);
}
index = end;
continue;
}
Expand All @@ -205,7 +213,7 @@ jobs:
continue;
}

rendered += line[index];
if (inlineTicks === null) rendered += line[index];
Comment thread
kyle-sexton marked this conversation as resolved.
index += 1;
}
output.push(rendered);
Expand Down
Loading