@hookform/resolvers 5.5.8 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.md +66 -64
  2. package/ajv/dist/ajv.js +1 -1
  3. package/ajv/dist/ajv.js.map +1 -1
  4. package/ajv/dist/ajv.mjs +1 -1
  5. package/ajv/dist/ajv.modern.mjs +1 -1
  6. package/ajv/dist/ajv.modern.mjs.map +1 -1
  7. package/ajv/dist/ajv.module.js +1 -1
  8. package/ajv/dist/ajv.module.js.map +1 -1
  9. package/ajv/dist/ajv.umd.js +1 -1
  10. package/ajv/dist/ajv.umd.js.map +1 -1
  11. package/ajv/src/__tests__/special-path-names.ts +27 -0
  12. package/ajv/src/ajv.ts +5 -1
  13. package/arktype/dist/arktype.js +1 -1
  14. package/arktype/dist/arktype.js.map +1 -1
  15. package/arktype/dist/arktype.mjs +1 -1
  16. package/arktype/dist/arktype.modern.mjs +1 -1
  17. package/arktype/dist/arktype.modern.mjs.map +1 -1
  18. package/arktype/dist/arktype.module.js +1 -1
  19. package/arktype/dist/arktype.module.js.map +1 -1
  20. package/arktype/dist/arktype.umd.js +1 -1
  21. package/arktype/dist/arktype.umd.js.map +1 -1
  22. package/arktype/src/__tests__/special-path-names.ts +21 -0
  23. package/arktype/src/arktype.ts +2 -1
  24. package/ata-validator/dist/ata-validator.js +1 -1
  25. package/ata-validator/dist/ata-validator.js.map +1 -1
  26. package/ata-validator/dist/ata-validator.mjs +1 -1
  27. package/ata-validator/dist/ata-validator.modern.mjs +1 -1
  28. package/ata-validator/dist/ata-validator.modern.mjs.map +1 -1
  29. package/ata-validator/dist/ata-validator.module.js +1 -1
  30. package/ata-validator/dist/ata-validator.module.js.map +1 -1
  31. package/ata-validator/dist/ata-validator.umd.js +1 -1
  32. package/ata-validator/dist/ata-validator.umd.js.map +1 -1
  33. package/ata-validator/src/__tests__/special-path-names.ts +45 -0
  34. package/ata-validator/src/ata-validator.ts +2 -1
  35. package/effect-ts/dist/effect-ts.js +1 -1
  36. package/effect-ts/dist/effect-ts.js.map +1 -1
  37. package/effect-ts/dist/effect-ts.mjs +1 -1
  38. package/effect-ts/dist/effect-ts.modern.mjs +1 -1
  39. package/effect-ts/dist/effect-ts.modern.mjs.map +1 -1
  40. package/effect-ts/dist/effect-ts.module.js +1 -1
  41. package/effect-ts/dist/effect-ts.module.js.map +1 -1
  42. package/effect-ts/dist/effect-ts.umd.js +1 -1
  43. package/effect-ts/dist/effect-ts.umd.js.map +1 -1
  44. package/effect-ts/src/__tests__/special-path-names.ts +23 -0
  45. package/effect-ts/src/effect-ts.ts +5 -1
  46. package/joi/dist/joi.js +1 -1
  47. package/joi/dist/joi.js.map +1 -1
  48. package/joi/dist/joi.mjs +1 -1
  49. package/joi/dist/joi.modern.mjs +1 -1
  50. package/joi/dist/joi.modern.mjs.map +1 -1
  51. package/joi/dist/joi.module.js +1 -1
  52. package/joi/dist/joi.module.js.map +1 -1
  53. package/joi/dist/joi.umd.js +1 -1
  54. package/joi/dist/joi.umd.js.map +1 -1
  55. package/joi/src/__tests__/special-path-names.ts +24 -0
  56. package/joi/src/joi.ts +6 -2
  57. package/package.json +4 -4
  58. package/typebox/dist/typebox.js +1 -1
  59. package/typebox/dist/typebox.js.map +1 -1
  60. package/typebox/dist/typebox.mjs +1 -1
  61. package/typebox/dist/typebox.modern.mjs +1 -1
  62. package/typebox/dist/typebox.modern.mjs.map +1 -1
  63. package/typebox/dist/typebox.module.js +1 -1
  64. package/typebox/dist/typebox.module.js.map +1 -1
  65. package/typebox/dist/typebox.umd.js +1 -1
  66. package/typebox/dist/typebox.umd.js.map +1 -1
  67. package/typebox/src/__tests__/special-path-names.ts +21 -0
  68. package/typebox/src/typebox.ts +2 -1
  69. package/typeschema/dist/typeschema.js +1 -1
  70. package/typeschema/dist/typeschema.js.map +1 -1
  71. package/typeschema/dist/typeschema.mjs +1 -1
  72. package/typeschema/dist/typeschema.modern.mjs +1 -1
  73. package/typeschema/dist/typeschema.modern.mjs.map +1 -1
  74. package/typeschema/dist/typeschema.module.js +1 -1
  75. package/typeschema/dist/typeschema.module.js.map +1 -1
  76. package/typeschema/dist/typeschema.umd.js +1 -1
  77. package/typeschema/dist/typeschema.umd.js.map +1 -1
  78. package/typeschema/src/__tests__/special-path-names.ts +21 -0
  79. package/typeschema/src/typeschema.ts +2 -1
  80. package/valibot/dist/valibot.js +1 -1
  81. package/valibot/dist/valibot.js.map +1 -1
  82. package/valibot/dist/valibot.mjs +1 -1
  83. package/valibot/dist/valibot.modern.mjs +1 -1
  84. package/valibot/dist/valibot.modern.mjs.map +1 -1
  85. package/valibot/dist/valibot.module.js +1 -1
  86. package/valibot/dist/valibot.module.js.map +1 -1
  87. package/valibot/dist/valibot.umd.js +1 -1
  88. package/valibot/dist/valibot.umd.js.map +1 -1
  89. package/valibot/src/__tests__/special-path-names.ts +21 -0
  90. package/valibot/src/valibot.ts +6 -2
  91. package/vest/dist/vest.js +1 -1
  92. package/vest/dist/vest.js.map +1 -1
  93. package/vest/dist/vest.mjs +1 -1
  94. package/vest/dist/vest.modern.mjs +1 -1
  95. package/vest/dist/vest.modern.mjs.map +1 -1
  96. package/vest/dist/vest.module.js +1 -1
  97. package/vest/dist/vest.module.js.map +1 -1
  98. package/vest/dist/vest.umd.js +1 -1
  99. package/vest/dist/vest.umd.js.map +1 -1
  100. package/vest/src/__tests__/special-path-names.ts +30 -0
  101. package/vest/src/vest.ts +2 -1
  102. package/vine/dist/vine.js +1 -1
  103. package/vine/dist/vine.js.map +1 -1
  104. package/vine/dist/vine.mjs +1 -1
  105. package/vine/dist/vine.modern.mjs +1 -1
  106. package/vine/dist/vine.modern.mjs.map +1 -1
  107. package/vine/dist/vine.module.js +1 -1
  108. package/vine/dist/vine.module.js.map +1 -1
  109. package/vine/dist/vine.umd.js +1 -1
  110. package/vine/dist/vine.umd.js.map +1 -1
  111. package/vine/package.json +1 -1
  112. package/vine/src/__tests__/Form-native-validation.tsx +4 -6
  113. package/vine/src/__tests__/Form.tsx +4 -6
  114. package/vine/src/__tests__/__fixtures__/data.ts +26 -28
  115. package/vine/src/__tests__/special-path-names.ts +23 -0
  116. package/vine/src/__tests__/vine.ts +13 -19
  117. package/vine/src/vine.ts +9 -7
  118. package/yup/dist/yup.js +1 -1
  119. package/yup/dist/yup.js.map +1 -1
  120. package/yup/dist/yup.mjs +1 -1
  121. package/yup/dist/yup.modern.mjs +1 -1
  122. package/yup/dist/yup.modern.mjs.map +1 -1
  123. package/yup/dist/yup.module.js +1 -1
  124. package/yup/dist/yup.module.js.map +1 -1
  125. package/yup/dist/yup.umd.js +1 -1
  126. package/yup/dist/yup.umd.js.map +1 -1
  127. package/yup/src/__tests__/special-path-names.ts +21 -0
  128. package/yup/src/yup.ts +5 -1
@@ -1,2 +1,2 @@
1
- !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@hookform/resolvers"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","react-hook-form"],o):o((e||self).hookformResolversYup={},e.hookformResolvers,e.ReactHookForm)}(this,function(e,o,t){e.yupResolver=function(e,r,n){return void 0===n&&(n={}),function(s,a,i){try{return Promise.resolve(function(t,u){try{var c=(null!=r&&r.context&&"development"===process.env.NODE_ENV&&console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"),Promise.resolve(e["sync"===n.mode?"validateSync":"validate"](s,Object.assign({abortEarly:!1},r,{context:a}))).then(function(e){return i.shouldUseNativeValidation&&o.validateFieldsNatively({},i),{values:n.raw?Object.assign({},s):e,errors:{}}}))}catch(e){return u(e)}return c&&c.then?c.then(void 0,u):c}(0,function(e){if(!e.inner)throw e;return{values:{},errors:o.toNestErrors((r=e,n=!i.shouldUseNativeValidation&&"all"===i.criteriaMode,(r.inner||[]).reduce(function(e,o){if(e[o.path]||(e[o.path]={message:o.message,type:o.type}),n){var r=e[o.path].types,s=r&&r[o.type];e[o.path]=t.appendErrors(o.path,n,e,o.type,s?[].concat(s,o.message):o.message)}return e},{})),i)};var r,n}))}catch(e){return Promise.reject(e)}}}});
1
+ !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@hookform/resolvers"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","react-hook-form"],o):o((e||self).hookformResolversYup={},e.hookformResolvers,e.ReactHookForm)}(this,function(e,o,t){e.yupResolver=function(e,r,n){return void 0===n&&(n={}),function(s,a,i){try{return Promise.resolve(function(t,u){try{var c=(null!=r&&r.context&&"development"===process.env.NODE_ENV&&console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"),Promise.resolve(e["sync"===n.mode?"validateSync":"validate"](s,Object.assign({abortEarly:!1},r,{context:a}))).then(function(e){return i.shouldUseNativeValidation&&o.validateFieldsNatively({},i),{values:n.raw?Object.assign({},s):e,errors:{}}}))}catch(e){return u(e)}return c&&c.then?c.then(void 0,u):c}(0,function(e){if(!e.inner)throw e;return{values:{},errors:o.toNestErrors((r=e,n=!i.shouldUseNativeValidation&&"all"===i.criteriaMode,(r.inner||[]).reduce(function(e,o){if(e[o.path]||(e[o.path]={message:o.message,type:o.type}),n){var r=e[o.path].types,s=r&&r[o.type];e[o.path]=t.appendErrors(o.path,n,e,o.type,s?[].concat(s,o.message):o.message)}return e},Object.create(null))),i)};var r,n}))}catch(e){return Promise.reject(e)}}}});
2
2
  //# sourceMappingURL=yup.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"yup.umd.js","sources":["../src/yup.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nfunction parseErrorSchema(\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean,\n) {\n return (error.inner || []).reduce<Record<string, FieldError>>(\n (previous, error) => {\n if (!previous[error.path!]) {\n previous[error.path!] = { message: error.message, type: error.type! };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[error.path!].types;\n const messages = types && types[error.type!];\n\n previous[error.path!] = appendErrors(\n error.path!,\n validateAllFieldCriteria,\n previous,\n error.type!,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n },\n {},\n );\n}\n\nexport function yupResolver<Input extends FieldValues, Context, Output>(\n schema:\n | Yup.ObjectSchema<Input, any, Output, any>\n | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<Input, any, Output, any>>>,\n schemaOptions?: Parameters<(typeof schema)['validate']>[1],\n resolverOptions?: {\n mode?: 'async' | 'sync';\n raw?: false;\n },\n): Resolver<\n Yup.InferType<typeof schema>,\n Context,\n Yup.InferType<typeof schema>\n>;\n\nexport function yupResolver<Input extends FieldValues, Context, Output>(\n schema:\n | Yup.ObjectSchema<Input, any, Output, any>\n | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<Input, any, Output, any>>>,\n schemaOptions: Parameters<(typeof schema)['validate']>[1] | undefined,\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw: true;\n },\n): Resolver<\n Yup.InferType<typeof schema>,\n Context,\n Yup.InferType<typeof schema>\n>;\n\n/**\n * Creates a resolver for react-hook-form using Yup schema validation\n * @param {Yup.ObjectSchema<TFieldValues> | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>} schema - Yup validation schema\n * @param {Parameters<(typeof schema)['validate']>[1]} schemaOptions - Options to pass to Yup's validate/validateSync\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {('async' | 'sync')} [resolverOptions.mode] - Validation mode\n * @param {boolean} [resolverOptions.raw] - If true, returns raw values instead of validated results\n * @returns {Resolver<Yup.InferType<typeof schema> | Input>} A resolver function compatible with react-hook-form\n * @example\n * const schema = Yup.object({\n * name: Yup.string().required(),\n * age: Yup.number().required(),\n * });\n *\n * useForm({\n * resolver: yupResolver(schema)\n * });\n */\nexport function yupResolver<Input extends FieldValues, Context, Output>(\n schema:\n | Yup.ObjectSchema<Input, any, Output, any>\n | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<Input, any, Output, any>>>,\n schemaOptions?: Parameters<(typeof schema)['validate']>[1],\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Yup.InferType<typeof schema> | Input> {\n return async (values: Input, context, options) => {\n try {\n if (schemaOptions?.context && process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\",\n );\n }\n\n const result = await schema[\n resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'\n ](\n values,\n Object.assign({ abortEarly: false }, schemaOptions, { context }),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result,\n errors: {},\n };\n } catch (e: any) {\n if (!e.inner) {\n throw e;\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n e,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n };\n}\n"],"names":["schema","schemaOptions","resolverOptions","values","context","options","Promise","resolve","process","env","NODE_ENV","console","warn","mode","Object","assign","abortEarly","then","result","shouldUseNativeValidation","validateFieldsNatively","raw","errors","_catch","e","inner","toNestErrors","error","validateAllFieldCriteria","criteriaMode","reduce","previous","path","message","type","types","messages","appendErrors","concat","reject"],"mappings":"sYA4FgB,SACdA,EAGAC,EACAC,GAKA,YALAA,IAAAA,IAAAA,EAGI,CAAE,GAEN,SAAcC,EAAeC,EAASC,OAAWC,OAAAA,QAAAC,iCAEzCN,MAAAA,GAAAA,EAAeG,SAAoC,gBAAzBI,QAAQC,IAAIC,UAExCC,QAAQC,KACN,iGAEHN,QAAAC,QAEoBP,EACM,SAAzBE,EAAgBW,KAAkB,eAAiB,YAEnDV,EACAW,OAAOC,OAAO,CAAEC,YAAY,GAASf,EAAe,CAAEG,QAAAA,MACvDa,cALKC,GASN,OAFAb,EAAQc,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEf,GAEzD,CACLF,OAAQD,EAAgBmB,IAAMP,OAAOC,OAAO,CAAE,EAAEZ,GAAUe,EAC1DI,OAAQ,CAAA,EACR,6DArB2CC,CAAA,EAsB9C,SAAQC,GACP,IAAKA,EAAEC,MACL,MAAMD,EAGR,MAAO,CACLrB,OAAQ,GACRmB,OAAQI,EAAYA,cArH1BC,EAuHUH,EAtHVI,GAuHWvB,EAAQc,2BACkB,QAAzBd,EAAQwB,cAtHZF,EAAMF,OAAS,IAAIK,OACzB,SAACC,EAAUJ,GAKT,GAJKI,EAASJ,EAAMK,QAClBD,EAASJ,EAAMK,MAAS,CAAEC,QAASN,EAAMM,QAASC,KAAMP,EAAMO,OAG5DN,EAA0B,CAC5B,IAAMO,EAAQJ,EAASJ,EAAMK,MAAOG,MAC9BC,EAAWD,GAASA,EAAMR,EAAMO,MAEtCH,EAASJ,EAAMK,MAASK,EAAYA,aAClCV,EAAMK,KACNJ,EACAG,EACAJ,EAAMO,KACNE,EACK,GAAgBE,OAAOF,EAAsBT,EAAMM,SACpDN,EAAMM,QAEd,CAEA,OAAOF,CACT,EACA,CAAE,IAiGI1B,IA5HV,IACEsB,EACAC,CA6HE,GACF,CAAC,MAAAJ,GAAA,OAAAlB,QAAAiC,OAAAf,EACH,CAAA,CAAA"}
1
+ {"version":3,"file":"yup.umd.js","sources":["../src/yup.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nfunction parseErrorSchema(\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean,\n) {\n // A null-prototype accumulator avoids false-positive hits from inherited\n // members (e.g. `toString`, `constructor`) when a field is named after\n // one of them — a plain `{}` would make `!previous[error.path!]`\n // truthy-skip those paths and silently drop their errors.\n return (error.inner || []).reduce<Record<string, FieldError>>(\n (previous, error) => {\n if (!previous[error.path!]) {\n previous[error.path!] = { message: error.message, type: error.type! };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[error.path!].types;\n const messages = types && types[error.type!];\n\n previous[error.path!] = appendErrors(\n error.path!,\n validateAllFieldCriteria,\n previous,\n error.type!,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n },\n Object.create(null),\n );\n}\n\nexport function yupResolver<Input extends FieldValues, Context, Output>(\n schema:\n | Yup.ObjectSchema<Input, any, Output, any>\n | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<Input, any, Output, any>>>,\n schemaOptions?: Parameters<(typeof schema)['validate']>[1],\n resolverOptions?: {\n mode?: 'async' | 'sync';\n raw?: false;\n },\n): Resolver<\n Yup.InferType<typeof schema>,\n Context,\n Yup.InferType<typeof schema>\n>;\n\nexport function yupResolver<Input extends FieldValues, Context, Output>(\n schema:\n | Yup.ObjectSchema<Input, any, Output, any>\n | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<Input, any, Output, any>>>,\n schemaOptions: Parameters<(typeof schema)['validate']>[1] | undefined,\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw: true;\n },\n): Resolver<\n Yup.InferType<typeof schema>,\n Context,\n Yup.InferType<typeof schema>\n>;\n\n/**\n * Creates a resolver for react-hook-form using Yup schema validation\n * @param {Yup.ObjectSchema<TFieldValues> | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>} schema - Yup validation schema\n * @param {Parameters<(typeof schema)['validate']>[1]} schemaOptions - Options to pass to Yup's validate/validateSync\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {('async' | 'sync')} [resolverOptions.mode] - Validation mode\n * @param {boolean} [resolverOptions.raw] - If true, returns raw values instead of validated results\n * @returns {Resolver<Yup.InferType<typeof schema> | Input>} A resolver function compatible with react-hook-form\n * @example\n * const schema = Yup.object({\n * name: Yup.string().required(),\n * age: Yup.number().required(),\n * });\n *\n * useForm({\n * resolver: yupResolver(schema)\n * });\n */\nexport function yupResolver<Input extends FieldValues, Context, Output>(\n schema:\n | Yup.ObjectSchema<Input, any, Output, any>\n | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<Input, any, Output, any>>>,\n schemaOptions?: Parameters<(typeof schema)['validate']>[1],\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Yup.InferType<typeof schema> | Input> {\n return async (values: Input, context, options) => {\n try {\n if (schemaOptions?.context && process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\",\n );\n }\n\n const result = await schema[\n resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'\n ](\n values,\n Object.assign({ abortEarly: false }, schemaOptions, { context }),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result,\n errors: {},\n };\n } catch (e: any) {\n if (!e.inner) {\n throw e;\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n e,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n };\n}\n"],"names":["schema","schemaOptions","resolverOptions","values","context","options","Promise","resolve","process","env","NODE_ENV","console","warn","mode","Object","assign","abortEarly","then","result","shouldUseNativeValidation","validateFieldsNatively","raw","errors","_catch","e","inner","toNestErrors","error","validateAllFieldCriteria","criteriaMode","reduce","previous","path","message","type","types","messages","appendErrors","concat","create","reject"],"mappings":"+YAiGEA,EAGAC,EACAC,GAKA,gBALAA,IAAAA,EAGI,IAEJ,SAAcC,EAAeC,EAASC,GAAO,WAAIC,QAAAC,uCAEzCN,GAAAA,EAAeG,SAAoC,gBAAzBI,QAAQC,IAAIC,UAExCC,QAAQC,KACN,iGAEHN,QAAAC,QAEoBP,EACM,SAAzBE,EAAgBW,KAAkB,eAAiB,YAEnDV,EACAW,OAAOC,OAAO,CAAEC,YAAY,GAASf,EAAe,CAAEG,QAAAA,MACvDa,KALKC,SAAAA,GASN,OAFAb,EAAQc,2BAA6BC,yBAAuB,CAAA,EAAIf,GAEzD,CACLF,OAAQD,EAAgBmB,IAAMP,OAAOC,OAAO,CAAA,EAAIZ,GAAUe,EAC1DI,OAAQ,GACR,6DArB2CC,CAAA,EAsB9C,SAAQC,GACP,IAAKA,EAAEC,MACL,MAAMD,EAGR,MAAO,CACLrB,OAAQ,GACRmB,OAAQI,EAAYA,cAzH1BC,EA2HUH,EA1HVI,GA2HWvB,EAAQc,2BACkB,QAAzBd,EAAQwB,cAtHZF,EAAMF,OAAS,IAAIK,OACzB,SAACC,EAAUJ,GAKT,GAJKI,EAASJ,EAAMK,QAClBD,EAASJ,EAAMK,MAAS,CAAEC,QAASN,EAAMM,QAASC,KAAMP,EAAMO,OAG5DN,EAA0B,CAC5B,IAAMO,EAAQJ,EAASJ,EAAMK,MAAOG,MAC9BC,EAAWD,GAASA,EAAMR,EAAMO,MAEtCH,EAASJ,EAAMK,MAASK,EAAYA,aAClCV,EAAMK,KACNJ,EACAG,EACAJ,EAAMO,KACNE,EACK,GAAgBE,OAAOF,EAAsBT,EAAMM,SACpDN,EAAMM,QAEd,CAEA,OAAOF,CACT,EACAjB,OAAOyB,OAAO,QAiGRlC,IAhIV,IACEsB,EACAC,CAiIE,GACF,CAAC,MAAAJ,GAAA,OAAAlB,QAAAkC,OAAAhB,EACH,CAAA,CAAA"}
@@ -0,0 +1,21 @@
1
+ import * as yup from 'yup';
2
+ import { yupResolver } from '..';
3
+
4
+ const shouldUseNativeValidation = false;
5
+
6
+ describe('yupResolver special path names', () => {
7
+ it.each(['hasOwnProperty', 'toString'])(
8
+ 'reports a validation error for a field named "%s"',
9
+ async (name) => {
10
+ const schema = yup.object({ [name]: yup.string().min(1).required() });
11
+
12
+ const result = await yupResolver(schema as any)(
13
+ { [name]: '' } as any,
14
+ undefined,
15
+ { fields: {}, shouldUseNativeValidation } as any,
16
+ );
17
+
18
+ expect(result.errors[name]).toBeDefined();
19
+ },
20
+ );
21
+ });
package/yup/src/yup.ts CHANGED
@@ -15,6 +15,10 @@ function parseErrorSchema(
15
15
  error: Yup.ValidationError,
16
16
  validateAllFieldCriteria: boolean,
17
17
  ) {
18
+ // A null-prototype accumulator avoids false-positive hits from inherited
19
+ // members (e.g. `toString`, `constructor`) when a field is named after
20
+ // one of them — a plain `{}` would make `!previous[error.path!]`
21
+ // truthy-skip those paths and silently drop their errors.
18
22
  return (error.inner || []).reduce<Record<string, FieldError>>(
19
23
  (previous, error) => {
20
24
  if (!previous[error.path!]) {
@@ -38,7 +42,7 @@ function parseErrorSchema(
38
42
 
39
43
  return previous;
40
44
  },
41
- {},
45
+ Object.create(null),
42
46
  );
43
47
  }
44
48