From 38e1a175b6d997d05bdc392db2600583456f9eb2 Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Mon, 1 Jun 2026 20:29:42 -0400 Subject: [PATCH] Harden settings UI: robust parentDir, escape browse paths, surface load error Co-Authored-By: Claude Opus 4.8 --- internal/web/static/app.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/internal/web/static/app.js b/internal/web/static/app.js index 0bf15d9..d862a5b 100644 --- a/internal/web/static/app.js +++ b/internal/web/static/app.js @@ -346,6 +346,12 @@ function openSettings() { document.getElementById('setSave').onclick = saveSettings; document.getElementById('setBrowse').onclick = () => loadBrowse(parentDir(document.getElementById('setKnow').value)); + }).catch(() => { + const ov = document.getElementById('settingsOverlay'); + ov.innerHTML = ''; + ov.hidden = false; + document.getElementById('setClose').onclick = closeSettings; }); } @@ -371,7 +377,13 @@ function saveSettings() { function parentDir(path) { if (!path) return ''; - return path.replace(/\/[^/]*$/, ''); + const i = path.lastIndexOf('/'); + if (i <= 0) return '/'; + return path.slice(0, i); +} + +function esc(s) { + return String(s).replace(/&/g, '&').replace(/ { const items = []; if (d.parent && d.parent !== d.dir) { - items.push(`
  • `); + items.push(`
  • `); } for (const e of d.entries) { if (e.is_dir) { - items.push(`
  • `); + items.push(`
  • `); } else { - items.push(`
  • `); + items.push(`
  • `); } } - pane.innerHTML = `
    ${d.dir}
    `; + pane.innerHTML = `
    ${esc(d.dir)}
    `; pane.querySelectorAll('button[data-dir]').forEach(b => b.onclick = () => loadBrowse(b.getAttribute('data-dir'))); pane.querySelectorAll('button[data-file]').forEach(b =>