Skip to content

Commit dca03da

Browse files
morinokamiclaude
andauthored
fix(env): pass Object.prototype members through the env proxy (#725)
When `env.ts` registers a schema, reading an `Object.prototype` member from `env` throws: ```ts import { env } from 'void/env'; env.hasOwnProperty('STRIPE_KEY'); env.constructor; String(env); ``` ``` TypeError: Cannot read properties of undefined (reading 'validate') ``` `readKey` looks the key up with `registry.schema[key]`, which also finds inherited members, and treats them as validators. Without a schema, the same expressions work. ## Fix `readKey` checks the key with `Object.hasOwn`, so these members pass through like any key the schema doesn't declare. ## Tests `packages/void/test/unit/env-schema.test.ts`: the three reads above with a registered schema. The case fails without this fix. ## Verification - `vp test run`: 776 files pass, 1 skipped (16,002 tests pass, 29 skipped). - `vp run check`: 33/33 pass. - By hand on a copy of `playground/ssr` with an `env.ts`: a route that makes these reads answers 200 in `vp dev` and `vp preview`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d4c4b49 commit dca03da

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)