Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string.matches throws error when we pass a string as second parameter #798

Closed
Grmiade opened this issue Mar 5, 2020 · 5 comments
Closed

Comments

@Grmiade
Copy link

Grmiade commented Mar 5, 2020

Describe the bug
In 0.28.1, these 2 signatures work:

  • string.matches(regex: Regex, message?: string | function): Schema
  • string.matches(regex: Regex, options: { message: string, excludeEmptyString: bool }): Schema

In 0.28.2:
The first one throws an error.
Cannot use 'in' operator to search for 'excludeEmptyString' in <message>

The bug has been introduced here: 27e5d68#diff-57c5960218f1091895b3610a7d779378R79

If options is a string, we cannot make this operation 'excludeEmptyString' in options.

To Reproduce

const schema = yup.string().matches(/test/, 'My message')
await schema.isValid('hi')

Expected behavior
Should not throw an error

@aaronhayes
Copy link

I am also the same issue with 0.28.2
TypeError: Cannot use 'in' operator to search for 'excludeEmptyString' in ${path} must be a website address

StringSchema.matches
node_modules/yup/es/string.js:93
  90 | var name;
  91 | 
  92 | if (options) {
> 93 |   if (options.message || 'excludeEmptyString' in options || options.name) {
     | ^  94 |     excludeEmptyString = options.excludeEmptyString;
  95 |     message = options.message;
  96 |     name = options.name;

@cameronmurphy
Copy link

Seeing this too

@puku0x
Copy link

puku0x commented Mar 6, 2020

I faced the same error after I updated yup to 0.28.2.

@kris2kris
Copy link

Same problem for me, rollback in 0.28.1 solve the problem

@gellati
Copy link

gellati commented Mar 6, 2020

I also had this error. The function expects an object, but a string is passed to it and therefore an error message is given. A rollback fixed the issue also for me, but I also made this pull request #801 for a suggested fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants