From 6d1756209b062d2f84e6d910ed8617b68a44ca9b Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Mon, 5 Oct 2026 00:34:32 +0200 Subject: [PATCH] Guard published journal against double-escaped apostrophes --- docs/viewer-publishing.md | 6 +++ test/journal-release-browser.mjs | 83 ++++++++++++++++++++++++++++++++ viewer/journal.js | 2 + 3 files changed, 91 insertions(+) create mode 100644 test/journal-release-browser.mjs diff --git a/docs/viewer-publishing.md b/docs/viewer-publishing.md index e23adb4..2e07b7b 100644 --- a/docs/viewer-publishing.md +++ b/docs/viewer-publishing.md @@ -9,3 +9,9 @@ BGS compresses JS, CSS, JSON and WASM automatically during upload. Send the orig The BGS admin's **Upload folder** control handles multi-file builds. For scripted releases, use BGS's `scripts/publish-viewer.mjs` with `--dir`, `--entry` and `--style`; it verifies every uploaded file, records the previous viewer, and activates only with `--apply --activate`. The full command and API contract are in the [BGS viewer documentation](https://docs.boardgamers.space/guide/viewer-api#publishing-a-viewer-with-multiple-files). English needs no language download; other languages load when selected. Test a cold load and a language change after publishing. Also check the browser Network panel for missing relative assets. + +Verify the uploaded entry itself with `node test/journal-release-browser.mjs viewer.json`, +where `viewer.json` contains the published viewer metadata. This checks journal +apostrophes and quoted player names before and after English/French switching. +An optional second argument supplies a candidate JS file at the existing entry URL +for a pre-publication check with the release's actual CSS and locale files. diff --git a/test/journal-release-browser.mjs b/test/journal-release-browser.mjs new file mode 100644 index 0000000..3a3b8d2 --- /dev/null +++ b/test/journal-release-browser.mjs @@ -0,0 +1,83 @@ +// Test the actual release artifact, including its relative locale downloads. +// Usage: node test/journal-release-browser.mjs viewer.json [candidate-viewer.js] +import assert from "node:assert/strict"; +import { readFile } from "node:fs/promises"; +import { chromium } from "playwright"; +import { prepared } from "../viewer/tutorials.js"; +import { stripSecret } from "../engine/index.js"; + +const viewer = JSON.parse(await readFile(process.argv[2], "utf8")); +const browser = await chromium.launch({ + executablePath: process.env.CHROMIUM_EXECUTABLE, +}); +try { + const page = await browser.newPage(); + const errors = []; + page.on("pageerror", (error) => errors.push(error.message)); + await page.route( + "https://boardgamers.space/__journal_release_check__", + (route) => + route.fulfill({ + contentType: "text/html; charset=utf-8", + body: '
', + }), + ); + if (process.argv[3]) { + const body = await readFile(process.argv[3], "utf8"); + await page.route(viewer.url, (route) => + route.fulfill({ contentType: "text/javascript; charset=utf-8", body }), + ); + } + await page.goto("https://boardgamers.space/__journal_release_check__"); + for (const url of viewer.dependencies?.stylesheets ?? []) + await page.addStyleTag({ url }); + await page.addScriptTag({ url: viewer.url }); + const state = prepared(); + const name = `O'Brien & "Co" `; + state.players[0].name = "dcobin"; + state.players[1].name = name; + state.log = [ + { round: 2, phase: 1, text: "The current is north. Ozone layer: 11." }, + { round: 2, phase: 2, text: "dcobin didn't buy any genes." }, + { round: 2, phase: 2, text: `${name} didn't buy any genes.` }, + ]; + await page.evaluate((state) => { + window.e = primordialSoup.launch("#app"); + e.emit("player", { index: 0 }); + e.emit("state", state); + }, stripSecret(state)); + const entry = page.locator(".journal-event").filter({ hasText: "dcobin" }); + await entry.waitFor(); + for (const locale of ["en", "fr", "en"]) { + await page.evaluate((locale) => e.emit("preferences", { locale }), locale); + const phase = locale === "fr" ? "Nouveaux gènes" : "New genes"; + await page.waitForFunction( + (phase) => + document.querySelector(".journal-list")?.textContent.includes(phase), + phase, + ); + const pass = + locale === "fr" ? "n’a acheté aucun gène." : "didn't buy any genes."; + assert.equal((await entry.textContent()).trim(), `dcobin ${pass}`); + assert.equal( + await entry + .locator("[data-localized-rich-text]") + .getAttribute("data-localized-rich-text"), + "dcobin didn't buy any genes.", + ); + assert.equal( + (await page.locator(".last-move").textContent()).trim(), + `${name} ${pass}`, + ); + assert.equal( + await page.locator(".journal-event img, .last-move img").count(), + 0, + ); + } + assert.deepEqual(errors, []); + console.log( + "Release journal: plain apostrophes, quoted player names and English/French switching passed", + ); +} finally { + await browser.close(); +} diff --git a/viewer/journal.js b/viewer/journal.js index 4abb82d..2738e68 100644 --- a/viewer/journal.js +++ b/viewer/journal.js @@ -180,6 +180,8 @@ export function renderJournalSentence( function journalSentence(source, players, omitSubject) { const data = players.map(({ name, color }) => ({ name, color })); + // Escape once: escaping # afterwards corrupts entities such as ' and + // makes localization render their encoded spelling instead of the apostrophe. return `${renderJournalSentence(source, data, undefined, omitSubject)}`; }