Skip to content

v4: .length() / .size() error messages ignore the exact flag #6176

Description

@itisrohit

Zod version

v4.4.3

Minimal reproduction

import { z } from "zod";

z.string().length(4).parse("abc");

Expected

Since .length(4) represents an exact constraint, the error message should indicate that the expected length is exactly 4, as it did in Zod v3.

Actual

The error message uses range wording (e.g. >=4 / <=4), even though the generated issue already contains exact: true.

Additional context

While investigating this, I found that:

  • exact: true is assigned for fixed-length validations in core/checks.ts.
  • exact is part of the too_small / too_big issue types.
  • None of the v4 locale renderers currently use issue.exact when formatting messages.
  • The v3 English locale did use issue.exact to produce messages such as "exactly 4".
  • I couldn't find an existing issue or PR covering this behavior.

Before opening a PR, I'd like to confirm whether this is an unintended regression. If so, I'd be happy to submit a focused PR updating the English locale together with the relevant tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions