Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

fix(updater): make the notes parser survive rendered HTML

chaitanyagiri34bbabde2159
diff --git a/src/shared/releaseNotes.ts b/src/shared/releaseNotes.ts
index 1937f1f6..c84577ed 100644
--- a/src/shared/releaseNotes.ts
+++ b/src/shared/releaseNotes.ts
@@ -66,6 +66,51 @@ const WHATS_NEW_RE = /^\s{0,3}#{1,6}\s+.*what[’']?s\s+new/i;
const FULL_CHANGELOG_RE = /^\s*\**\s*full\s+changelog\s*\**\s*:/i;
const BARE_URL_RE = /^\s*<?https?:\/\/\S+>?\s*$/i;
+/**
+ * GitHub's releases.atom feed carries the release body as RENDERED HTML, not as
+ * the markdown that produced it, and electron-updater falls back to that feed
+ * whenever the channel yml has no releaseNotes. So this parser has to survive
+ * HTML even though every one of its tests fed it markdown.
+ *
+ * Untreated, rendered HTML has no `##` headings, so the what's-new section is
+ * never found and the bullet scan takes over. In OUR body the only line that
+ * looks like a markdown bullet is `* { box-sizing: border-box; }` from the
+ * <style> block, because `*` followed by a space IS the bullet syntax. The
+ * shipped toast said exactly that and nothing else.
+ *
+ * Belt and braces only: the real fix is releaseInfo.releaseNotesFile in
+ * electron-builder.yml, which puts markdown in the yml so the feed is never
+ * read. This just makes a future release that forgets the yml degrade to
+ * something correct rather than to CSS.
+ */
+const STYLE_SCRIPT_RE = /<(style|script)\b[^>]*>[\s\S]*?<\/\1>/gi;
+const HTML_HEADING_RE = /^\s*<h[1-6]\b[^>]*>/i;
+const HTML_LI_RE = /^\s*<li\b[^>]*>/i;
+/** Only the apostrophe forms, decoded early so WHATS_NEW_RE still matches
+ * `<h2>What&#39;s new</h2>`. Deliberately NOT &lt;/&gt;, which would
+ * manufacture tags out of escaped text. */
+const APOS_ENTITY_RE = /&(?:#0*39|#x0*27|apos|rsquo|lsquo);/gi;
+
+/** A heading in either syntax. */
+function isHeadingLine(line: string): boolean {
+ return HEADING_RE.test(line) || HTML_HEADING_RE.test(line);
+}
+
+/** The what's-new heading in either syntax. */
+function isWhatsNewLine(line: string): boolean {
+ if (WHATS_NEW_RE.test(line)) return true;
+ return HTML_HEADING_RE.test(line) && /what[’']?s\s+new/i.test(line);
+}
+
+/** The bullet marker this line opens with, in either syntax, or null. */
+function bulletPrefix(line: string): string | null {
+ if (RULE_RE.test(line)) return null;
+ const md = line.match(BULLET_RE);
+ if (md) return md[0];
+ const li = line.match(HTML_LI_RE);
+ return li ? li[0] : null;
+}
+
/**
* Markdown → plain text for one already-joined line.
*
@@ -111,7 +156,13 @@ function isMeaningful(text: string): boolean {
function usableLines(body: string): string[] {
const out: string[] = [];
let inFence = false;
- for (const raw of body.replace(/\r\n?/g, '\n').split('\n')) {
+ // Whole blocks, before any line splitting: a <style> body is CSS on every one
+ // of its lines, and one of those lines parses as a markdown bullet.
+ const cleaned = body
+ .replace(/\r\n?/g, '\n')
+ .replace(STYLE_SCRIPT_RE, '')
+ .replace(APOS_ENTITY_RE, "'");
+ for (const raw of cleaned.split('\n')) {
if (FENCE_RE.test(raw)) { inFence = !inFence; continue; }
if (inFence) continue;
const line = raw
@@ -135,13 +186,13 @@ function usableLines(body: string): string[] {
* preamble and END the section once content has been collected.
*/
function firstSection(lines: string[]): string[] {
- const marker = lines.findIndex((l) => WHATS_NEW_RE.test(l));
+ const marker = lines.findIndex(isWhatsNewLine);
const start = marker >= 0 ? marker + 1 : 0;
const out: string[] = [];
let seenContent = false;
for (let i = start; i < lines.length; i++) {
const line = lines[i];
- if (HEADING_RE.test(line) || RULE_RE.test(line)) {
+ if (isHeadingLine(line) || RULE_RE.test(line)) {
if (seenContent) break;
continue;
}
@@ -175,10 +226,10 @@ function collectItems(section: string[]): string[] {
for (const line of section) {
if (line.trim() === '') { flush(); continue; }
- const bullet = line.match(BULLET_RE);
- if (bullet && !RULE_RE.test(line)) {
+ const bullet = bulletPrefix(line);
+ if (bullet) {
flush();
- current = [line.slice(bullet[0].length)];
+ current = [line.slice(bullet.length)];
currentIsBullet = true;
} else if (current.length > 0) {
current.push(line.trim()); // a wrapped continuation of the item above
diff --git a/test/release-notes.test.cjs b/test/release-notes.test.cjs
index 3982a98d..1777ff2b 100644
--- a/test/release-notes.test.cjs
+++ b/test/release-notes.test.cjs
@@ -239,6 +239,82 @@ test('options are honoured so a roomier surface can ask for more', () => {
assert.ok(total(summarizeReleaseNotes(body, { maxChars: 60 })) <= 60);
});
+/**
+ * The production input, which every test above this line got wrong.
+ *
+ * electron-updater only falls back to GitHub's releases.atom feed when the
+ * channel yml carries no releaseNotes — and that feed's `<content type="html">`
+ * is GitHub's RENDERED HTML of RELEASE.md, not its markdown source. Every
+ * fixture above feeds markdown, so the suite was green while production was
+ * broken: no `##` headings meant no what's-new section, the bullet scan took
+ * over, and the only line in 53KB matching the bullet syntax was
+ * `* { box-sizing: border-box; }` from RELEASE.md's <style> block, because `*`
+ * plus a space IS a markdown bullet. Users saw a CSS rule as the entire list.
+ *
+ * The shipped fix is releaseInfo.releaseNotesFile (below), which puts markdown
+ * in the yml so the feed is never consulted. These pin the fallback anyway, so
+ * a release that forgets the yml degrades to correct instead of to CSS.
+ */
+const RENDERED_ATOM_HTML = [
+ '<style>',
+ ' * { box-sizing: border-box; }',
+ ' .md-body { margin: 0; padding: 0; }',
+ '</style>',
+ '<h1>Munder Difflin v0.4.6</h1>',
+ '<p>A local hive of agents that run themselves.</p>',
+ '<h2>What&#39;s new in 0.4.6</h2>',
+ '<ul>',
+ '<li><strong>The interface speaks Chinese.</strong> Pick zh-CN in Settings.</li>',
+ '<li><strong>IME typing no longer sends early.</strong> Enter picks your candidate.</li>',
+ '<li><strong>Fonts ship inside the app.</strong> No Google Fonts fetch on launch.</li>',
+ '</ul>',
+ '<h2>Downloads</h2>',
+ '<table><tr><td>macOS</td><td>Apple silicon</td></tr></table>'
+].join('\n');
+
+test('rendered HTML from the atom feed never yields CSS', () => {
+ const digest = summarizeReleaseNotes(RENDERED_ATOM_HTML);
+
+ // The exact string the founder was shown.
+ assert.ok(
+ !digest.some((l) => /box-sizing/.test(l)),
+ `a CSS rule reached the toast: ${JSON.stringify(digest)}`
+ );
+ for (const line of digest) {
+ assert.doesNotMatch(line, /[{};]/, 'a stylesheet fragment reached the toast');
+ assert.doesNotMatch(line, /^\s*</, 'a raw HTML tag reached the toast');
+ }
+});
+
+test('rendered HTML yields the actual news, not the preamble or the downloads', () => {
+ const digest = summarizeReleaseNotes(RENDERED_ATOM_HTML);
+
+ assert.equal(digest.length, 3);
+ assert.match(digest[0], /^The interface speaks Chinese\./);
+ assert.match(digest[1], /^IME typing no longer sends early\./);
+ assert.match(digest[2], /^Fonts ship inside the app\./);
+ // `<h2>What&#39;s new` has to be recognised through the entity, or the
+ // section marker is missed and the <h1>/<p> preamble leads instead.
+ assert.ok(!digest.some((l) => /A local hive|Munder Difflin v/.test(l)));
+ // The section has to END at the next <h2>, exactly as it does at `##`.
+ assert.ok(!digest.some((l) => /Downloads|Apple silicon/.test(l)));
+});
+
+test('a <style> block is dropped even with no what-is-new heading to anchor on', () => {
+ const body = [
+ '<style>',
+ ' * { box-sizing: border-box; }',
+ '</style>',
+ '<ul><li>Fixes the crash on launch.</li></ul>'
+ ].join('\n');
+ assert.deepEqual(summarizeReleaseNotes(body), ['Fixes the crash on launch.']);
+ // <script> gets the same treatment; it is never prose.
+ assert.deepEqual(
+ summarizeReleaseNotes('<script>\nvar a = 1;\n</script>\n\n- Real news here.'),
+ ['Real news here.']
+ );
+});
+
test('the notes file we actually ship fits the toast', () => {
// Guards the FILE, not the parser: build/release-notes.md is what
// releaseInfo.releaseNotesFile bakes into latest*.yml, and it is the thing a