Skip to content

fix(ajv): preserve escaped field names in validation errors - #879

Merged
jorisre merged 1 commit into
react-hook-form:masterfrom
Marve10s:fix/ajv-json-pointer-paths
Oct 17, 2026
Merged

jorisre merged 1 commit into
react-hook-form:masterfrom
Marve10s:fix/ajv-json-pointer-paths

Conversation

@Marve10s

Copy link
Copy Markdown
Contributor

Proposed Changes

AJV resolver errors for fields containing / or ~ are returned under encoded or incorrectly nested names. React Hook Form cannot associate those errors with the registered field or its ref.

Decode each JSON Pointer token before constructing the RHF path. Keep a required property's already-decoded name as a single segment so it is neither split at / nor decoded twice.

Reproduction on 5.9.1:

import { ajvResolver } from '@hookform/resolvers/ajv';

const schema = {
  type: 'object',
  properties: { 'a/b': { type: 'string' } },
  required: ['a/b'],
};
const { errors } = await ajvResolver(schema)(
  { 'a/b': 1 },
  undefined,
  { fields: {}, shouldUseNativeValidation: false },
);
console.log(Object.keys(errors));

Before: ['a~1b']. After: ['a/b']. A missing required a/b also stays under that field instead of becoming errors.a.b.

A frozen install currently fails on unchanged master because package.json requires ATA validator ^1.23.0 while bun.lock records ^1.2.0. The manifest and lockfile are unchanged by this PR.

@bluebill1049
bluebill1049 requested a review from jorisre October 16, 2026 23:10
@jorisre
jorisre merged commit 71e6052 into react-hook-form:master Oct 17, 2026
2 of 3 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

馃帀 This PR is included in version 5.9.2 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants