fix(triage): use word-boundary matching in parseChangelog per spec

This commit is contained in:
diegosouzapw
2026-05-19 02:41:38 -03:00
parent 22400a4f86
commit 8cca3630ae
2 changed files with 16 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ const VERSION_HEADER_RE = /^##\s+\[?(\d+\.\d+\.\d+)\]?/;
export function parseChangelog(text, issueNumber) {
if (typeof text !== "string") return null;
if (!Number.isInteger(issueNumber) || issueNumber <= 0) return null;
const needle = `#${issueNumber}`;
const lines = text.split("\n");
@@ -18,9 +19,14 @@ export function parseChangelog(text, issueNumber) {
currentVersion = headerMatch[1];
continue;
}
if (line.includes(needle) && currentSection) {
const match = line.match(/\(#\d+\)/);
if (match && match[0] === `(${needle})`) {
if (!currentSection) continue;
// Match #N with word boundary: look for needle followed by non-word char or end
const idx = line.indexOf(needle);
if (idx !== -1) {
const nextIdx = idx + needle.length;
const nextChar = line[nextIdx];
const isWordBoundary = nextIdx >= line.length || /\W/.test(nextChar);
if (isWordBoundary) {
return {
section: currentSection,
version: currentVersion,

View File

@@ -39,4 +39,11 @@ describe("parseChangelog", () => {
const r = parseChangelog(text, 980);
assert.equal(r.version, "3.7.2");
});
it("matches #N with word boundary (not only inside parentheses)", () => {
const text = `## [3.7.2]\n- Fixed by #980.\n`;
const r = parseChangelog(text, 980);
assert.equal(r.version, "3.7.2");
assert.match(r.line, /#980/);
});
});