diff --git a/lib/system-status.js b/lib/system-status.js index 4f00c52..682b6b4 100644 --- a/lib/system-status.js +++ b/lib/system-status.js @@ -210,10 +210,15 @@ customElements.define('system-status', class extends HTMLElement { const pathQuery = spawnSync('reg', ['query', 'HKCU\\Environment', '/v', 'Path']) if (pathQuery.status !== 0 && !pathQuery.stderr.toString().includes('unable to find')) { - throw new Error('Failed to query user PATH.') + throw new Error('Failed to query user PATH') } - const originalPath = pathQuery.stdout.toString()?.match(WIN_REGVAL_MATCHER)?.[1] + const pathMatches = pathQuery.stdout.toString()?.match(WIN_REGVAL_MATCHER) + if (!Array.isArray(pathMatches) || pathMatches.length !== 2) { + throw new Error('Failed to extract user PATH') + } + + const originalPath = pathMatches[1] if (!originalPath || !originalPath.includes(BIN)) { const newPath = originalPath ? `${BIN};${originalPath}` : BIN spawnSync('reg', ['add', 'HKCU\\Environment', '/v', 'Path', '/t', 'REG_SZ', '/d', newPath, '/f'])