Merge pull request #3594 from ketpatil77/fix/managed-hook-config-bom

fix(hooks): honor managed preferences in BOM-prefixed config
This commit is contained in:
haelyra authored and GitHub committed 2026-10-25 17:44:47 -04:00
commit e3292b0010
2 files changed
+17 -1

No files matched your search

+1 -1
View File
@@ -48,7 +48,7 @@ function readManagedHookConfig(env = process.env) {
if (!configPath || !fs.existsSync(configPath)) return {};
try {
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
const config = JSON.parse(fs.readFileSync(configPath, 'utf8').replace(/^\uFEFF/, ''));
return config?.hooks
&& typeof config.hooks === 'object'
&& !Array.isArray(config.hooks)
+16
View File
@@ -162,6 +162,22 @@ function runTests() {
}
})) passed++; else failed++;
if (test('managed hook config accepts a leading UTF-8 BOM', () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-hook-flags-bom-'));
const configPath = path.join(root, 'setup.json');
const env = { ECC_HOOK_CONFIG: configPath };
try {
fs.writeFileSync(configPath, '\uFEFF' + JSON.stringify({
hooks: { enabled: false, profile: 'minimal', note: 'keep\uFEFFinside' },
}));
assert.strictEqual(areHooksEnabled(env), false);
assert.strictEqual(getHookProfile(env), 'minimal');
assert.strictEqual(readManagedHookConfig(env).note, 'keep\uFEFFinside');
} finally {
fs.rmSync(root, { recursive: true, force: true });
}
})) passed++; else failed++;
if (test('a hook evaluation reads managed config only once', () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-hook-flags-read-once-'));
const configPath = path.join(root, 'setup.json');