question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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: https://github.com/jquense/yup/commit/27e5d684acb7563fa44c4da6baa8e81c94a08c34#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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:14
  • Comments:5

github_iconTop GitHub Comments

4reactions
gellaticommented, 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.

2reactions
kris2kriscommented, Mar 6, 2020

Same problem for me, rollback in 0.28.1 solve the problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java - Trying to throw an error based on 2 string values in the ...
The first part of the code seems to work but the second part is saying its always true and I get an error...
Read more >
Regular Expressions :: Eloquent JavaScript
If you pass it a string, it will return a Boolean telling you whether the string contains a match of the pattern in...
Read more >
4. Pattern Matching with Regular Expressions - Java ... - O'Reilly
In the second frame, I have finished typing the regex, and typed the data string as QA577 (which you should expect to match...
Read more >
String (Java Platform SE 8 ) - Oracle Help Center
Allocates a new String so that it represents the sequence of characters currently contained in the character array argument. String(char[] value, int offset, ......
Read more >
String.prototype.charAt() - JavaScript - MDN Web Docs
The String object's charAt() method returns a new string consisting of the ... (str.length <= i + 1) { throw new Error("High surrogate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found