Skip to content

fix: remove inaccurate and unnecessary regexp used by unknown-options-as-args #508

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

Merged
merged 2 commits into from
Jul 29, 2025

Conversation

shadowspawn
Copy link
Member

@shadowspawn shadowspawn commented Jul 25, 2025

isUnknownOption contained three similar regular expressions about characters after a flag. After investigation, and consistent with the examples in the comments, I believe they are related to short option group processing (so the -+ at start of pattern is too permissive). But in fact they are not needed at all, because the cases are covered by hasAllShortFlags()!

      // e.g. '-a-'
      const flagEndingInHyphen = /^-+([^=]+?)-$/
      // e.g. '-abc123'
      const flagEndingInDigits = /^-+([^=]+?\d+)$/
      // e.g. '-a/usr/local'
      const flagEndingInNonWordCharacters = /^-+([^=]+?)\W+.*$/

After deleting the expressions all the existing tests still pass. Also fixes #501. I have copied across the tests from #502 and added @Xunnamius as a co-author on this PR.

Resolves #501
Closes #502

@shadowspawn shadowspawn changed the title fix: remove broken and unnecessary regexp used by unknown-options-as-args fix: remove inaccurate and unnecessary regexp used by unknown-options-as-args Jul 26, 2025
@bcoe bcoe merged commit cea8972 into yargs:main Jul 29, 2025
8 checks passed
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

Successfully merging this pull request may close these issues.

Incorrect parsing of unknown args with dashes when they resemble known args
2 participants