Skip to content

Conversation

@bgk614
Copy link
Contributor

@bgk614 bgk614 commented Jan 14, 2026

Summary

Fixes mutation of user-provided ctx parameter in parse functions by replacing Object.assign with object spread syntax.

Problem

Using Object.assign(_ctx, {…}) mutates the original context object passed by the user.

Before Example:

const ctx: schemas.ParseContextInternal = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };

After Example:

const ctx: schemas.ParseContextInternal = _ctx ? { ..._ctx, async: false } : { async: false };

Affected Functions

  • _parse
  • _parseAsync
  • _safeParseAsync
  • _encode
  • _encodeAsync
  • _safeEncode
  • _safeEncodeAsync

Note: _safeParse already used spread operator.

Changes

  • packages/zod/src/v4/core/parse.ts - Replace Object.assign with spread operator
  • packages/zod/src/v4/classic/tests/codec.test.ts - Add context immutability tests

Fixes #5466

@pullfrog
Copy link
Contributor

pullfrog bot commented Jan 14, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant