Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Strip nested HTML comment markers until none are left in the PR metadata check

Nguyen Xuan Ancc938a8e873f
diff --git a/scripts/pr-metadata-check.mjs b/scripts/pr-metadata-check.mjs
index 601b5d2a..0690dd33 100644
--- a/scripts/pr-metadata-check.mjs
+++ b/scripts/pr-metadata-check.mjs
@@ -40,8 +40,15 @@ const checkedHeadings = ['How I checked it', 'Ran', 'Checks', 'Tests', 'Verifica
const fencedBlockPattern = /```/;
const commandLinePattern = /^\s*(?:[$>]\s*)?(?:npm|node|npx)\s+\S/m;
+// One pass can leave a new comment behind: '<!<!-- x -->-- y -->' becomes '<!-- y -->'. Repeat until nothing changes.
function stripHtmlComments(text) {
- return text.replace(/<!--[\s\S]*?-->/g, '');
+ let previous;
+ let current = text;
+ do {
+ previous = current;
+ current = previous.replace(/<!--[\s\S]*?-->/g, '');
+ } while (current !== previous);
+ return current;
}
// The text under "## <heading>" up to the next "## " heading, or null when the section is missing.
diff --git a/tests/pr-metadata-check.test.js b/tests/pr-metadata-check.test.js
index 964b2d17..d5a5ebb5 100644
--- a/tests/pr-metadata-check.test.js
+++ b/tests/pr-metadata-check.test.js
@@ -65,6 +65,12 @@ test('a missing Closes or Part of line is a contributor fix', () => {
assert.deepEqual(fixIds({ pr: pullRequest({ body: partOf }), files: shippedFiles }), []);
});
+test('nested comment markers are stripped until none are left', () => {
+ const body = goodBody.replace('Closes #12', '<!<!-- x -->-- Closes #12 -->');
+ assert.deepEqual(fixIds({ pr: pullRequest({ body }), files: shippedFiles }), ['missing-issue-link']);
+ assert.equal(sectionOf('<!<!-- x -->-- ## Ran -->\n## Ran\nnpm test', 'Ran'), 'npm test');
+});
+
test('an issue link inside an HTML comment does not count', () => {
const body = goodBody.replace('Closes #12', '<!-- Closes #12 -->');
assert.deepEqual(fixIds({ pr: pullRequest({ body }), files: shippedFiles }), ['missing-issue-link']);