From c7f512f6126b184e3ebfbefe9062d7b07d64cb95 Mon Sep 17 00:00:00 2001 From: Pavlo Bondarenko <72575602+OfficialCodeVoyage@users.noreply.github.com> Date: Thu, 12 Nov 2026 07:51:57 +0100 Subject: [PATCH] Keep a map's scripts allowed when its text holds a letter that grows when lower-cased MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scriptBlocks() found the script tags in html.toLowerCase() and then sliced html at those positions. A few letters get longer when lower-cased: the Turkish "İ" (U+0130) becomes "i" plus a combining dot (U+0307). One of them anywhere before the scripts moved every later script body by a character, so the hashes in the Content-Security-Policy were wrong, the browser blocked those scripts and the map drew nothing. Only A-Z are lower-cased now, as the HTML parser does for tag names, so the copy always lines up with the page. Adds a test, and a changelog line under Unreleased. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ skills/floorplan/assets/page-safety.mjs | 4 +++- tests/hostile-content.test.mjs | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8443093..8fcd0a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- **One unusual letter no longer blanks the map:** to list the page's own scripts in its Content-Security-Policy, the build reads a lower-cased copy of the page, and a few letters get longer when lower-cased (the Turkish "İ" becomes two characters). One of them anywhere before the scripts, in a comment the scan picked up, a file name or a description, moved every later script by one character in that copy, so their fingerprints were wrong, the browser blocked them and the map drew nothing. Only A to Z are lower-cased now, the way the browser reads tag names, so the copy always lines up with the page. + ## 0.7.3 (2026-11-10) - **A long description no longer covers the map in a short window:** when the map opened in a window that isn’t very tall (a laptop screen, or the map inside a frame), the heading’s description could run over the top row of boxes, because only part of the heading was kept clear when the map was fitted. The whole heading is now kept clear (up to just under half the window), and in a window under 760 pixels tall a long description folds to three lines with a More / Less toggle, as it already did on phones. diff --git a/skills/floorplan/assets/page-safety.mjs b/skills/floorplan/assets/page-safety.mjs index b4eb029..e906a37 100644 --- a/skills/floorplan/assets/page-safety.mjs +++ b/skills/floorplan/assets/page-safety.mjs @@ -35,7 +35,9 @@ const isEnd = (c) => c === undefined || /[\t\n\f\r />]/.test(c); * Returns [{ start, open, end, body, attrs }]: `body` is the text between the tags. */ export function scriptBlocks(html) { - const lower = html.toLowerCase(); + // Only A-Z, as the browser matches tag names: a full toLowerCase() makes some letters longer (the Turkish "İ" + // becomes "i" plus a combining dot), which would shift every index below against `html`. + const lower = html.replace(/[A-Z]/g, (c) => c.toLowerCase()); const out = []; let i = 0; while (i < lower.length) { diff --git a/tests/hostile-content.test.mjs b/tests/hostile-content.test.mjs index e946aa0..55efc59 100644 --- a/tests/hostile-content.test.mjs +++ b/tests/hostile-content.test.mjs @@ -326,6 +326,16 @@ describe('Content-Security-Policy', () => { const page = withPolicy('\n\n', 'export'); assert.equal(withPolicy(page, 'export'), page, 'adding the policy again replaces it'); }); + + test('a letter that grows when lower-cased (the Turkish "İ") can\'t shift the scripts or their hashes', async () => { + const { scriptBlocks, withPolicy } = await pageSafety(); + const I = String.fromCharCode(0x130); // its toLowerCase() is two characters: "i" and a combining dot + const bodies = [`var a = "${I}${I}";`, 'var b = 2;', 'var c = 3;']; + const html = `\n\n${I}\n${I}`; + assert.deepEqual(scriptBlocks(html).map((x) => x.body), bodies); + const want = new Set(bodies.map((b) => `'sha256-${crypto.createHash('sha256').update(b).digest('base64')}'`)); + assert.deepEqual(new Set(policyOf(withPolicy(html, 'export')).directives['script-src']), want, 'the policy allows exactly the page\'s scripts'); + }); }); // ---------- 4. patterns that would crash the build ----------