Guard published journal against double-escaped apostrophes
This commit is contained in:
parent
ed6325b7f5
commit
6d1756209b
3 changed files with 91 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
83
test/journal-release-browser.mjs
Normal file
83
test/journal-release-browser.mjs
Normal file
|
|
@ -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: '<html lang="en"><body><div id="app"></div></body></html>',
|
||||
}),
|
||||
);
|
||||
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" <img src=x>`;
|
||||
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();
|
||||
}
|
||||
|
|
@ -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 `<span data-localized-rich-text="${escape(source)}" data-journal-players="${escape(JSON.stringify(data))}"${omitSubject ? ` data-journal-omit-subject="${escape(JSON.stringify(omitSubject))}"` : ""} translate="no">${renderJournalSentence(source, data, undefined, omitSubject)}</span>`;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue