Skip to content

See how your app actually fits together. An interactive, plain-English map of your codebase, drawn by Claude or Codex.

Fix the six CodeQL findings

Hayden Smithc213813131a5
diff --git a/skills/floorplan/assets/serve.mjs b/skills/floorplan/assets/serve.mjs
index 90632b8..8770a31 100644
--- a/skills/floorplan/assets/serve.mjs
+++ b/skills/floorplan/assets/serve.mjs
@@ -43,7 +43,7 @@ const DATA_START = '<script>window.FLOORPLAN = ';
function exportMap(include, extraFlows = []) {
const html = fs.readFileSync(path.join(here, 'index.html'), 'utf8');
const a = html.indexOf(DATA_START), b = html.indexOf(';</script>', a);
- if (a < 0 || b < 0) throw new Error('This map is too old to export. Ask Claude or Codex to update the floorplan first.');
+ if (a < 0 || b < 0) throw Object.assign(new Error('This map is too old to export. Ask Claude or Codex to update the floorplan first.'), { plain: true });
const g = JSON.parse(html.slice(a + DATA_START.length, b));
const on = EXPORT_PARTS.filter((p) => include.includes(p));
const out = {
@@ -500,7 +500,10 @@ function undoChange() {
if (!all.length) return { ok: false, error: 'Nothing to undo.' };
const dir = path.join(historyDir, all[all.length - 1]);
restore(dir);
- try { skillScript('plan.mjs'); skillScript('build.mjs', '--no-claude-md'); } catch (e) { return { ok: false, error: String(e.message || e).slice(0, 500) }; }
+ try { skillScript('plan.mjs'); skillScript('build.mjs', '--no-claude-md'); } catch (e) {
+ console.error(`✗ Undo couldn't redraw the plan: ${e.message || e}`);
+ return { ok: false, error: 'Couldn’t redraw the previous plan. The details are in the map server’s output.' };
+ }
fs.rmSync(dir, { recursive: true, force: true });
return { ok: true, left: all.length - 1 };
}
@@ -575,7 +578,11 @@ const server = http.createServer((req, res) => {
const x = exportMap(Array.isArray(body.include) ? body.include.map(String) : EXPORT_DEFAULT, cleanFlows(body.flows));
res.writeHead(200, { 'Content-Type': TYPES['.html'], 'Content-Disposition': `attachment; filename="${x.name}"`, 'Cache-Control': 'no-store' });
res.end(x.html);
- } catch (e) { res.writeHead(500, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: e.message })); }
+ } catch (e) {
+ console.error(`✗ Couldn't export the map: ${e.message}`);
+ res.writeHead(500, { 'Content-Type': 'application/json' });
+ res.end(JSON.stringify({ error: e.plain ? e.message : 'The map’s server couldn’t export it. The details are in its output.' }));
+ }
});
return;
}
diff --git a/skills/floorplan/assets/viewer.html b/skills/floorplan/assets/viewer.html
index 586eaa9..bcdda2d 100644
--- a/skills/floorplan/assets/viewer.html
+++ b/skills/floorplan/assets/viewer.html
@@ -2036,7 +2036,11 @@ if (EXPORTED) {
const made = document.createElement('a');
made.id = 'madewith'; made.className = 'glass';
made.href = 'https://github.com/haydenschmitty/floorplan'; made.target = '_blank'; made.rel = 'noopener';
- made.innerHTML = `Made with <img class="mark" src="${$('.brand .mark').src}" alt=""><b>Floorplan</b><span class="x">· free and open source</span>`;
+ const logo = $('.brand .mark').cloneNode();
+ logo.alt = '';
+ const name = document.createElement('b'); name.textContent = 'Floorplan';
+ const free = document.createElement('span'); free.className = 'x'; free.textContent = '· free and open source';
+ made.append('Made with', logo, name, free);
$('#stage').appendChild(made);
}
document.title = `${G.project.name} map`;
diff --git a/skills/floorplan/scripts/lib/common.mjs b/skills/floorplan/scripts/lib/common.mjs
index b68994e..d6a3da0 100644
--- a/skills/floorplan/scripts/lib/common.mjs
+++ b/skills/floorplan/scripts/lib/common.mjs
@@ -37,7 +37,7 @@ export function globToRegExp(glob) {
if (c === '[' && (i === 0 || g[i - 1] === '/')) {
const end = g.indexOf('/', i) < 0 ? g.length : g.indexOf('/', i);
const seg = g.slice(i, end);
- if (/^\[\[?(\.\.\.)?[A-Za-z_$][\w$-]*\]\]?$/.test(seg)) { re += seg.replace(/[.[\]$]/g, '\\$&'); i = end; continue; }
+ if (/^\[\[?(\.\.\.)?[A-Za-z_$][\w$-]*\]\]?$/.test(seg)) { re += seg.replace(/[.[\]$\\]/g, '\\$&'); i = end; continue; }
}
if (c === '[') {
const j = g.indexOf(']', i + 1);
diff --git a/skills/floorplan/scripts/lib/extract.mjs b/skills/floorplan/scripts/lib/extract.mjs
index f3b3712..4b14efc 100644
--- a/skills/floorplan/scripts/lib/extract.mjs
+++ b/skills/floorplan/scripts/lib/extract.mjs
@@ -279,7 +279,7 @@ function callableCalls(code, at) {
/** Uses of a callable helper: `callFunction('approveItem', data)` → CALL /approveItem. */
function callsVia(code, name, skipLine = 0) {
const out = [];
- const re = new RegExp(`(?<![\\w$.])${name.replace(/\$/g, '\\$')}\\s*(?:<[^;]{0,300}?>)?\\s*\\(\\s*(["'\`])([\\w-]+)\\1`, 'g');
+ const re = new RegExp(`(?<![\\w$.])${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*(?:<[^;]{0,300}?>)?\\s*\\(\\s*(["'\`])([\\w-]+)\\1`, 'g');
const at = lineIndex(code);
for (const m of code.matchAll(re)) {
const line = at(m.index);
diff --git a/skills/floorplan/scripts/lib/resolve.mjs b/skills/floorplan/scripts/lib/resolve.mjs
index 20306d9..79d4273 100644
--- a/skills/floorplan/scripts/lib/resolve.mjs
+++ b/skills/floorplan/scripts/lib/resolve.mjs
@@ -78,7 +78,7 @@ export function createResolver(root, files) {
: (spec.startsWith(pattern.slice(0, star)) && spec.endsWith(pattern.slice(star + 1)) ? spec.slice(star, spec.length - (pattern.length - star - 1)) : null);
if (matched === null) continue;
for (const t of targets) {
- const hit = tryJsFile(P.join(cfg.baseDir, t.replace('*', matched)));
+ const hit = tryJsFile(P.join(cfg.baseDir, t.split('*').join(matched)));
if (hit) return { file: hit };
}
}
diff --git a/tests/theme.test.mjs b/tests/theme.test.mjs
index ddec98f..46619f7 100644
--- a/tests/theme.test.mjs
+++ b/tests/theme.test.mjs
@@ -11,7 +11,10 @@ let root, html;
before(() => { root = shopApp(); scanAndBuild(root); html = fs.readFileSync(path.join(root, 'floorplan', 'index.html'), 'utf8'); });
after(() => cleanup(root));
-const bootScript = () => html.match(/<script>\s*\/\* Theme: runs before[\s\S]*?<\/script>/)[0].replace(/^<script>|<\/script>$/g, '');
+const bootScript = () => {
+ const at = html.indexOf('/* Theme: runs before');
+ return html.slice(html.lastIndexOf('<script>', at) + '<script>'.length, html.indexOf('</script>', at));
+};
/** Runs the boot script with a pretend device and returns what it did to the page. */
function boot({ saved, deviceLight = false, storageThrows = false } = {}) {