const assert = require('node:assert/strict'); const fs = require('node:fs'); const os = require('node:os'); const path = require('node:path'); const {spawnSync} = require('node:child_process'); const index = fs.readFileSync('web/templates/index.html', 'utf8'); const base = fs.readFileSync('web/templates/base.html', 'utf8'); function extract(source, name) { const match = source.match(new RegExp(`^( *)(?:async )?function ${name}\\(`, 'm')); assert(match, `Missing function ${name}`); const end = source.indexOf(`\n${match[1]}}`, match.index); assert(end > match.index); return source.slice(match.index, end + match[1].length + 2); } const functions = [ ...['renderMultiSelectTab', 'renderMultiSelectTabWithSections', 'renderRentalTab', '_renderBOMParsedTable'].map(n => extract(index, n)), ...['showToast', 'loadSyncInfo', 'repairPendingChanges'].map(n => extract(base, n)), ].join('\n'); const ids = new Set([...functions.matchAll(/getElementById\('([^']+)'\)/g)].map(m => m[1])); const fixtures = [...ids].map(id => id.endsWith('-body') ? `
([\s\S]*?)<\/pre>/)?.[1];
assert.equal(outcome, 'PASS', outcome || 'Browser did not finish');
console.log('Browser HTML security regressions passed');
} finally {
fs.rmSync(directory, {recursive: true, force: true});
}