Skip to content

Don't blank the map when the code holds a letter that grows when lower-cased (like "İ") - #118

Merged
haydenschmitty merged 1 commit into
haydenschmitty:mainfrom
OfficialCodeVoyage:fix/csp-hash-lowercase-length
Nov 15, 2026
Merged

haydenschmitty merged 1 commit into
haydenschmitty:mainfrom
OfficialCodeVoyage:fix/csp-hash-lowercase-length

Conversation

@OfficialCodeVoyage

Copy link
Copy Markdown
Contributor

What this changes

The map opened blank on a project whose code holds a Turkish "İ" in a comment. The browser console showed "Executing inline script violates the following Content Security Policy directive" for every inline script after the map's data.

Cause: scriptBlocks() in assets/page-safety.mjs finds the script tags in html.toLowerCase(), then slices html at those positions. A few letters get longer when lower-cased: "İ".toLowerCase() (U+0130) is two characters, "i" plus a combining dot (U+0307). So one such letter anywhere before the scripts (in a comment the scan picked up, a file name or a description) moves every later script body by one character. The hashes in the policy no longer match what the browser hashes, and it blocks those scripts.

Fix: lower-case only A to Z, the way the HTML parser matches tag names, so the copy is always the same length as the page:

const lower = html.replace(/[A-Z]/g, (c) => c.toLowerCase());

Every name the function looks for (script, style, title, textarea, <!--) is ASCII, so nothing else changes. No issue was filed first; this PR describes the bug.

How I tested it

  • A real project: a TypeScript Next.js app, one repo, about 1,800 mapped files, where one comment holds an "İ". With 0.7.3, the browser blocked 12 of the page's 16 inline scripts and the map was blank. With this change, all 16 hashes match, the console shows no errors, and the map, panels and tour draw normally.
  • A new test in tests/hostile-content.test.mjs: an "İ" in the title, inside a script and in the body, with an upper-case <SCRIPT>. scriptBlocks() returns the exact bodies, and the policy allows exactly their hashes. The test fails on main and passes with the change.
  • npm test: 286 pass, 0 fail, 1 skipped (the Windows-only claude.exe test), on macOS with Node 24.
  • claude plugin validate . passes.

Checklist

  • No new dependencies
  • Anything the map shows people is in plain language
  • No secret values stored or printed
  • No details of a real private project in code, comments, docs or screenshots
  • npm test passes
  • claude plugin validate . passes
  • CHANGELOG.md updated, if people will notice the change

🤖 Generated with Claude Code

…when lower-cased

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 <noreply@anthropic.com>
@haydenschmitty
haydenschmitty merged commit 2d283c7 into haydenschmitty:main Nov 15, 2026
@haydenschmitty

Copy link
Copy Markdown
Owner

Merged and released in 0.10.0. Thank you for the clear write-up!

Update with claude plugin update floorplan@floorplan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants