nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: jquense/yup
Pull request #198 (2018-04-17 15:46:35)

fix getDefault so it respects the context passed into it


Patch:
diff --git a/src/mixed.js b/src/mixed.js
index 4e74ec2..62c0b20 100644
--- a/src/mixed.js
+++ b/src/mixed.js
@@ -302,8 +302,9 @@ SchemaType.prototype = {
     }
   },
 
-  getDefault({ context, parent }) {
-    return this._resolve(context, parent).default();
+  getDefault(options = {}) {
+    let schema = this.resolve(options);
+    return schema.default();
   },
 
   default(def) {


Test patch:
diff --git a/test/mixed.js b/test/mixed.js
index aafd443..2a82996 100644
--- a/test/mixed.js
+++ b/test/mixed.js
@@ -64,6 +64,19 @@ describe('Mixed Types ', () => {
     inst.cast(undefined).should.equal('hello');
   });
 
+  it('getDefault should return the default value', function() {
+    let inst = string().default('hi');
+    inst.getDefault({}).should.equal('hi');
+    inst.getDefault().should.equal('hi');
+  });
+  it('getDefault should return the default value', function() {
+    let inst = string().when('$foo', {
+      is: 'greet',
+      then: string().default('hi'),
+    });
+    inst.getDefault({ context: { foo: 'greet' } }).should.equal('hi');
+  });
+
   it('should warn about null types', async () => {
     let error = await string()
       .strict()
Repository: jquense/yup
Pull request #403 (2018-12-18 16:03:53)

fix: cast() does not work well if scheme has stripped field.
This is the small fix for #342: cast() returns new value even if nothing has changed, but scheme has a stripped field.


Patch:
diff --git a/src/object.js b/src/object.js
index 61f6db7..2ca5108 100644
--- a/src/object.js
+++ b/src/object.js
@@ -104,7 +104,7 @@ inherits(ObjectSchema, MixedSchema, {
         field = field.resolve(innerOptions);
 
         if (field._strip === true) {
-          isChanged = true;
+          isChanged = isChanged || prop in value;
           return;
         }
 


Test patch:
diff --git a/test/object.js b/test/object.js
index 02acfb3..3e4484f 100644
--- a/test/object.js
+++ b/test/object.js
@@ -23,6 +23,7 @@ describe('Object types', () => {
         dte: date(),
         nested: object().shape({ str: string() }),
         arrNested: array().of(object().shape({ num: number() })),
+        stripped: string().strip(),
       });
     });
Repository: jquense/yup
Pull request #405 (2018-12-19 20:35:47)

Replace integer check with Number.isInteger
This works correctly for large numbers.

Related to https://github.com/jquense/yup/pull/147

mAAdhaTTah: I'm not sure what your policy is for using newer features. I can inline the `Number.isInteger` polyfill from MDN if that's preferred. Or I can update the docs to indicate this is required so the user makes sure it's supported or is polyfilled.
mAAdhaTTah: Looking at the test failure, I'm not sure why that was considered invalid.
mAAdhaTTah: Addressed the comment & resolved the conflict.
mAAdhaTTah: @jquense Bumping this. I think I've addressed your issues. Let me know if you've got other changes.

Patch:
diff --git a/src/number.js b/src/number.js
index be65452..b179e6a 100644
--- a/src/number.js
+++ b/src/number.js
@@ -5,8 +5,6 @@ import isAbsent from './util/isAbsent';
 
 let isNaN = value => value != +value;
 
-let isInteger = val => isAbsent(val) || val === (val | 0);
-
 export default function NumberSchema() {
   if (!(this instanceof NumberSchema)) return new NumberSchema();
 
@@ -14,8 +12,8 @@ export default function NumberSchema() {
 
   this.withMutation(() => {
     this.transform(function(value) {
-      let parsed = value
-      
+      let parsed = value;
+
       if (typeof parsed === 'string') {
         parsed = parsed.replace(/\s/g, '');
         if (parsed === '') return NaN;
@@ -94,7 +92,11 @@ inherits(NumberSchema, MixedSchema, {
   },
 
   integer(message = locale.integer) {
-    return this.test({ name: 'integer', message, test: isInteger });
+    return this.test({
+      name: 'integer',
+      message,
+      test: val => isAbsent(val) || Number.isInteger(val),
+    });
   },
 
   truncate() {


Test patch:
diff --git a/test/number.js b/test/number.js
index 4d9144b..651873d 100644
--- a/test/number.js
+++ b/test/number.js
@@ -203,8 +203,8 @@ describe('Number types', function() {
     var schema = number().integer();
 
     TestHelpers.validateAll(schema, {
-      valid: [4, -5222],
-      invalid: [10.53, 0.1 * 0.2, -34512535.626, 3.12312e51, new Date()],
+      valid: [4, -5222, 3.12312e51],
+      invalid: [10.53, 0.1 * 0.2, -34512535.626, new Date()],
     });
 
     it('should return default message', () => {
Repository: jquense/yup
Pull request #410 (2018-12-31 14:35:07)

fix: validate() does not work with ref and abortEarly false. (#409)
Commented change on #409 to dont break Promise.all chain


Patch:
diff --git a/src/object.js b/src/object.js
index 2ca5108..332910d 100644
--- a/src/object.js
+++ b/src/object.js
@@ -163,6 +163,7 @@ inherits(ObjectSchema, MixedSchema, {
             innerOptions.strict = true;
 
             if (field.validate) return field.validate(value[key], innerOptions);
+            return Promise.resolve(true);
           }
 
           return true;


Test patch:
diff --git a/test/object.js b/test/object.js
index 3e4484f..543fd39 100644
--- a/test/object.js
+++ b/test/object.js
@@ -382,6 +382,24 @@ describe('Object types', () => {
     });
   });
 
+  it('should allow refs with abortEarly false', async () => {
+    let schema = object().shape({
+      field: string(),
+      dupField: ref('field'),
+    });
+
+    let actual = await schema
+      .validate(
+        {
+          field: 'test',
+        },
+        { abortEarly: false },
+      )
+      .should.not.be.rejected();
+
+    actual.should.eql({ field: 'test', dupField: 'test' });
+  });
+
   describe('lazy evaluation', () => {
     let types = {
       string: string(),
Repository: jquense/yup
Pull request #452 (2019-02-07 06:07:22)

fix: noUnknown() overriding
Right now `noUnknown()` changes `_options.stripUnknown` only when `noAllow` is true. So when `noAllow` is `false` in override the option still remains `true`.


Patch:
diff --git a/src/object.js b/src/object.js
index f8b3f96..417e83b 100644
--- a/src/object.js
+++ b/src/object.js
@@ -240,7 +240,7 @@ inherits(ObjectSchema, MixedSchema, {
       },
     });
 
-    if (noAllow) next._options.stripUnknown = true;
+    next._options.stripUnknown = noAllow;
 
     return next;
   },


Test patch:
diff --git a/test/object.js b/test/object.js
index 543fd39..2069d51 100644
--- a/test/object.js
+++ b/test/object.js
@@ -329,6 +329,17 @@ describe('Object types', () => {
     ]);
   });
 
+  it('should work with noUnknown override', async () => {
+    let inst = object()
+      .shape({
+        prop: mixed(),
+      })
+      .noUnknown()
+      .noUnknown(false);
+
+    await inst.validate({ extra: 'field' }).should.become({ extra: 'field' });
+  });
+
   it('should strip specific fields', () => {
     let inst = object().shape({
       prop: mixed().strip(false),
Repository: jquense/yup
Pull request #669 (2019-10-22 14:44:33)

Fix array path resolve for descendants
At the moment during casting process Array type passes the field path to sub items without resolving it according to sub item array index.
The path is exposed to end consumer as part of context in conditional validation `when` (could be somewhere else).
If conditional validation relies on context path - this behaviour will lead to bugs.


Patch:
diff --git a/src/array.js b/src/array.js
index c053963..e66fead 100644
--- a/src/array.js
+++ b/src/array.js
@@ -46,8 +46,11 @@ inherits(ArraySchema, MixedSchema, {
     if (!this._typeCheck(value) || !this._subType) return value;
 
     let isChanged = false;
-    const castArray = value.map(v => {
-      const castElement = this._subType.cast(v, _opts);
+    const castArray = value.map((v, idx) => {
+      const castElement = this._subType.cast(v, {
+        ..._opts,
+        path: makePath`${_opts.path}[${idx}]`,
+      });
       if (castElement !== v) {
         isChanged = true;
       }


Test patch:
diff --git a/test/array.js b/test/array.js
index ff303ef..5c3bec5 100644
--- a/test/array.js
+++ b/test/array.js
@@ -175,4 +175,19 @@ describe('Array types', () => {
 
     inst.cast(null).should.eql([]);
   });
+
+  it('should pass resolved path to descendants', async () => {
+    let value = ['2', '3'];
+    let expectedPaths = ['[0]', '[1]'];
+
+    let itemSchema = string().when([], function(_, context) {
+      let path = context.path || '';
+      path.should.be.oneOf(expectedPaths);
+      return string().required();
+    });
+
+    await array()
+      .of(itemSchema)
+      .validate(value);
+  });
 });
Repository: jquense/yup
Pull request #1060 (2020-10-06 14:00:34)

Solves typing issues in prependDeep + allow JS for incremental transition to Typescript


Patch:
diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 0000000..9e2b401
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1,2 @@
+.eslintrc
+.eslintrc.js
diff --git a/src/Schema.ts b/src/Schema.ts
index 0afe1f8..3bb30a3 100644
--- a/src/Schema.ts
+++ b/src/Schema.ts
@@ -2,8 +2,7 @@ import { ResolveOptions } from './Condition';
 import {
   ValidateOptions,
   Callback,
-  MessageParams,
-  AnyMessageParams,, ExtraParams
+  ExtraParams
 } from './types';
 
 export interface CastOptions {
diff --git a/src/index.ts b/src/index.ts
index cc6ec1d..eefb22b 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,10 +1,6 @@
 import MixedSchema, {
   create as mixedCreate,
-  ResolveCast,
   SchemaSpec,
-  ResolveRequired,
-  Asserts,
-  TypeOf,
 } from './mixed';
 import BoolSchema, { create as boolCreate } from './boolean';
 import StringSchema, { create as stringCreate } from './string';
diff --git a/src/util/prependDeep.ts b/src/util/prependDeep.ts
index ab875b8..99bfaf3 100644
--- a/src/util/prependDeep.ts
+++ b/src/util/prependDeep.ts
@@ -1,5 +1,5 @@
 import has from 'lodash/has';
-import isSchema from './isSchema';
+import { MixedSchema } from '..';
 
 // function has<T extends {}, Key extends PropertyKey>
 //   (obj: T, prop: Key): obj is T & Record<Key, unknown> {
@@ -22,8 +22,8 @@ export default function merge(
         target[key] = sourceVal;
       } else if (targetVal === sourceVal) {
         continue;
-      } else if (isSchema(targetVal)) {
-        if (isSchema(sourceVal)) target[key] = sourceVal.concat(targetVal);
+      } else if (targetVal instanceof MixedSchema) {
+        if (sourceVal instanceof MixedSchema) target[key] = sourceVal.concat(targetVal);
       } else if (isObject(targetVal)) {
         if (isObject(sourceVal)) target[key] = merge(targetVal, sourceVal);
       } else if (Array.isArray(targetVal)) {
diff --git a/tsconfig.json b/tsconfig.json
index f6f1135..1b619a9 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,6 +1,7 @@
 {
   "extends": "@4c/tsconfig/web.json",
   "compilerOptions": {
+    "allowJs": true,
     "rootDir": "src"
   },
   "include": ["src"]


Test patch:
diff --git a/test/.eslintignore b/test/.eslintignore
new file mode 100644
index 0000000..9e2b401
--- /dev/null
+++ b/test/.eslintignore
@@ -0,0 +1,2 @@
+.eslintrc
+.eslintrc.js
diff --git a/test/yup.js b/test/yup.js
index 69264d5..45b3b56 100644
--- a/test/yup.js
+++ b/test/yup.js
@@ -1,6 +1,5 @@
 import reach, { getIn } from '../src/util/reach';
 import prependDeep from '../src/util/prependDeep';
-import * as Async from '../src/util/async';
 
 import { object, array, string, lazy, number, ValidationError } from '../src';
Repository: jquense/yup
Pull request #1327 (2021-04-04 16:43:02)

fix: prevent unhandled Promise rejection when returning rejected Promise inside test function
Fixes https://github.com/jquense/yup/issues/1326


Patch:
diff --git a/src/util/createValidation.ts b/src/util/createValidation.ts
index a6cefef..3df3728 100644
--- a/src/util/createValidation.ts
+++ b/src/util/createValidation.ts
@@ -120,7 +120,7 @@ export default function createValidation(config: {
           if (ValidationError.isError(validOrError)) cb(validOrError);
           else if (!validOrError) cb(createError());
           else cb(null, validOrError);
-        });
+        }).catch(cb);
       } catch (err) {
         cb(err);
       }


Test patch:
diff --git a/test/mixed.js b/test/mixed.js
index 01ae82a..f422405 100644
--- a/test/mixed.js
+++ b/test/mixed.js
@@ -529,6 +529,16 @@ describe('Mixed Types ', () => {
       });
   });
 
+  it('should fail when the test function returns a rejected Promise', async () => {
+    let inst = string().test(() => {
+      return Promise.reject(new Error('oops an error occurred'))
+    });
+
+    return inst
+      .validate('joe')
+      .should.be.rejected();
+  });
+
   describe('withMutation', () => {
     it('should pass the same instance to a provided function', () => {
       let inst = mixed();
Repository: jquense/yup
Pull request #1824 (2022-11-07 21:40:08)

fix: string().notRequired()
In a project, we need to undo some `.required()` fields in `.when()`-conditions, but for `string()` that does not work 🙈.

This should fix it. 🤞 

Thank you for your work maintaining this validation library (coming here from the Formik-recommendation). 💚 

jquense: Thanks!

Patch:
diff --git a/src/string.ts b/src/string.ts
index 1cde8d4..beceeb3 100644
--- a/src/string.ts
+++ b/src/string.ts
@@ -97,7 +97,7 @@ export default class StringSchema<
 
   notRequired() {
     return super.notRequired().withMutation((schema: this) => {
-      schema.tests.filter((t) => t.OPTIONS!.name !== 'required');
+      schema.tests = schema.tests.filter((t) => t.OPTIONS!.name !== 'required');
       return schema;
     });
   }


Test patch:
diff --git a/test/string.ts b/test/string.ts
index 2e7f322..ab0ad3e 100644
--- a/test/string.ts
+++ b/test/string.ts
@@ -94,6 +94,15 @@ describe('String types', () => {
     ]);
   });
 
+  it('should handle NOTREQUIRED correctly', function () {
+    let v = string().required().notRequired();
+
+    return Promise.all([
+      expect(v.isValid(undefined)).resolves.toBe(true),
+      expect(v.isValid('')).resolves.toBe(true),
+    ]);
+  });
+
   it('should check MATCHES correctly', function () {
     let v = string().matches(/(hi|bye)/, 'A message');