From 779a18f56e6aef873c2a80fd36b3f05d6e8cc089 Mon Sep 17 00:00:00 2001 From: LyAhn Date: Sun, 21 Jun 2026 08:48:19 +0100 Subject: [PATCH] fix: use valid end-of-input anchor in changelog-add MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JS regex has no \z anchor — it matched a literal 'z', so appending to the last section under [Unreleased] silently failed and duplicated the heading. Use $(?![\s\S]) to anchor to true end-of-input. --- tools/changelog-add.mjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/changelog-add.mjs b/tools/changelog-add.mjs index cb24c92..242cd8f 100644 --- a/tools/changelog-add.mjs +++ b/tools/changelog-add.mjs @@ -45,7 +45,9 @@ if (!/^## \[Unreleased\]/m.test(changelog)) { ); } -const unreleasedMatch = changelog.match(/^## \[Unreleased\][\s\S]*?(?=^## \[|\z)/m); +// JS regex has no \z anchor, so match to the next version heading or true +// end-of-input ($ with nothing following — \n-tolerant under the m flag). +const unreleasedMatch = changelog.match(/^## \[Unreleased\][\s\S]*?(?=^## \[|$(?![\s\S]))/m); if (!unreleasedMatch) { throw new Error("Could not find or create an Unreleased section."); } @@ -55,7 +57,7 @@ const lineEnding = changelog.includes("\r\n") ? "\r\n" : "\n"; const bullet = `- ${message}`; let nextUnreleased; -const sectionRegex = new RegExp(`(^### ${section}\\s*)([\\s\\S]*?)(?=^### |\\z)`, "m"); +const sectionRegex = new RegExp(`(^### ${section}\\s*)([\\s\\S]*?)(?=^### |$(?![\\s\\S]))`, "m"); const sectionMatch = unreleased.match(sectionRegex); if (sectionMatch) {