Skip to content

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