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

fix: duplicated patterns in second phase preprocess loop #235

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

ziqiq
Copy link
Contributor

@ziqiq ziqiq commented Jun 12, 2024

This patch removes a potential duplication in the level 2 optimization.

To reproduce, evaluate following:

new Minimatch("{a,b,*}", {optimizationLevel: 2})

Current upstream has an extra "b" in set and globParts:

Minimatch {
  options: { optimizationLevel: 2 },
  set: [ [ /^(?!\.)[^/]+?$/ ], [ 'b' ] ],
  pattern: '{a,b,*}',
  windowsPathsNoEscape: false,
  nonegate: false,
  negate: false,
  comment: false,
  empty: false,
  preserveMultipleSlashes: false,
  partial: false,
  globSet: [ 'a', 'b', '*' ],
  globParts: [ [ '*' ], [ 'b' ] ],
  nocase: false,
  isWindows: false,
  platform: 'darwin',
  windowsNoMagicRoot: false,
  regexp: null
}

This patch:

Minimatch {
  options: { optimizationLevel: 2 },
  set: [ [ /^(?!\.)[^/]+?$/ ] ],
  pattern: '{a,b,*}',
  windowsPathsNoEscape: false,
  nonegate: false,
  negate: false,
  comment: false,
  empty: false,
  preserveMultipleSlashes: false,
  partial: false,
  globSet: [ 'a', 'b', '*' ],
  globParts: [ [ '*' ] ],
  nocase: false,
  isWindows: false,
  platform: 'darwin',
  windowsNoMagicRoot: false,
  regexp: null
}

@isaacs
Copy link
Owner

isaacs commented Jun 25, 2024

That clearly is an improvement, but can you add a test that would highlight the difference? You can re-generate snapshots with npm run snap, and then include the changed snapshot in the PR, so probably all that has to be done is to add {a,*,b} to the existing test cases somewhere.

@isaacs isaacs closed this in f09ab67 Jun 25, 2024
@isaacs isaacs merged commit f09ab67 into isaacs:main Jun 25, 2024
@isaacs
Copy link
Owner

isaacs commented Jun 25, 2024

Nevermind, just added the test myself :)

thanks!

afzalimdad9 added a commit to afzalimdad9/minimatch that referenced this pull request Jan 18, 2025
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.

2 participants