Skip to content

Commit d7e6bb2

Browse files
committed
fix(installer): reject invalid claude settings roots
1 parent 9f37a5d commit d7e6bb2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

scripts/lib/install/apply.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ function mergeHooksIntoSettings(plan) {
4949
if (fs.existsSync(settingsPath)) {
5050
try {
5151
settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
52+
if (!settings || typeof settings !== 'object' || Array.isArray(settings)) {
53+
throw new Error('root value must be a JSON object');
54+
}
5255
} catch (error) {
5356
throw new Error(`Failed to parse existing settings at ${settingsPath}: ${error.message}`);
5457
}

tests/scripts/install-apply.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,27 @@ function runTests() {
441441
}
442442
})) passed++; else failed++;
443443

444+
if (test('fails when existing settings.json root is not an object', () => {
445+
const homeDir = createTempDir('install-apply-home-');
446+
const projectDir = createTempDir('install-apply-project-');
447+
448+
try {
449+
const claudeRoot = path.join(homeDir, '.claude');
450+
fs.mkdirSync(claudeRoot, { recursive: true });
451+
const settingsPath = path.join(claudeRoot, 'settings.json');
452+
fs.writeFileSync(settingsPath, '[]\n');
453+
454+
const result = run(['--profile', 'core'], { cwd: projectDir, homeDir });
455+
assert.strictEqual(result.code, 1);
456+
assert.ok(result.stderr.includes('Failed to parse existing settings at'));
457+
assert.ok(result.stderr.includes('root value must be a JSON object'));
458+
assert.strictEqual(fs.readFileSync(settingsPath, 'utf8'), '[]\n');
459+
} finally {
460+
cleanup(homeDir);
461+
cleanup(projectDir);
462+
}
463+
})) passed++; else failed++;
464+
444465
if (test('installs from ecc-install.json and persists component selections', () => {
445466
const homeDir = createTempDir('install-apply-home-');
446467
const projectDir = createTempDir('install-apply-project-');

0 commit comments

Comments
 (0)