Skip to content

Documentation is unclear for excludeEmptyString option #2110

Description

@jdsandifer

Describe the bug
The documentation seems to disagree with itself - the description doesn't match the example provided (which seems correct based on testing).

To Reproduce

Read this section of the docs:

string.matches(regex: Regex, options: { message: string, excludeEmptyString: bool }): Schema
An alternate signature for string.matches with an options object. excludeEmptyString, when true, short circuits the regex test when the value is an empty string, making it a easier to avoid matching nothing without complicating the regex.

let schema = string().matches(/(hi|bye)/, { excludeEmptyString: true });

await schema.isValid(''); // => true

In particular, the "easier to avoid matching nothing without complicating the regex" part seems to suggest empty strings would not validate. (Opposite of observed behavior.)

Expected behavior
Setting excludeEmptyString to true allows/validates empty strings even if they don't match the regex so the documentation should clearly state that.

Perhaps something like "... excludeEmptyString, when true, short circuits the regex so empty strings pass validation without complicating the regex."

Platform (please complete the following information):

  • Browser: Chrome 116
  • Yup Version: 1.0.2

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions