mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-05 14:52:09 +03:00
fix(triage): use word-boundary matching in parseChangelog per spec
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user