Skip to content

Commit daa0e23

Browse files
morinokamiclaude
andcommitted
fix(env): pass Object.prototype members through the env proxy
`readKey` looked keys up with `registry.schema[key]`, which also finds inherited members. With a schema registered, `env.hasOwnProperty`, `env.constructor` and `String(env)` treated those members as validators and threw a TypeError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent afcc6d0 commit daa0e23

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎packages/void/src/runtime/env-public.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ function readKey(key: string): unknown {
252252
if (!registry.schema) {
253253
return rawValue;
254254
}
255-
const validator = registry.schema[key];
255+
// `env.hasOwnProperty` and the like come from Object.prototype, not from the schema.
256+
const validator = Object.hasOwn(registry.schema, key) ? registry.schema[key] : undefined;
256257
if (!validator) {
257258
return rawValue;
258259
}

‎packages/void/test/unit/env-schema.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ describe('defineEnv + env proxy', () => {
127127
});
128128
});
129129

130+
it('passes through Object.prototype members without validation', () => {
131+
defineEnv({ STRIPE_KEY: string() });
132+
withRuntimeEnv({ STRIPE_KEY: 'sk' }, () => {
133+
expect(env.hasOwnProperty).toBe(Object.prototype.hasOwnProperty);
134+
expect(env.constructor).toBe(Object);
135+
expect(String(env)).toBe('[object Object]');
136+
});
137+
});
138+
130139
it('caches validated values per env identity (no re-validation)', () => {
131140
let calls = 0;
132141
const inner = string();

0 commit comments

Comments
 (0)