micromatch / micromatch/picomatch

Negation doesn't properly invert matching of patterns

Open
#148 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.3k
Forks
135
Avg merge
23h 38m
Merged PRs (30d)
7

Description

Here's a very simple set of test cases. Based on my understanding of negation, !(<some pattern>) should precisely invert the results of (<some pattern>), i.e. any path that matches the first should not match the second, and vice versa. This is not the case.

const pm = require('picomatch');

function test(matcher, path) {
    const matches = matcher(path) ? '✓' : '✗';
    console.log(`${matches}: ${path}`);
}

const tests = ['foo', 'foo/.bar', '.bar', '.foo/.bar'];

function testGlob(glob) {
    const matcher = pm(glob);
    console.log(glob)
    tests.forEach(t => test(matcher, t));
    console.log('')
}

testGlob('.*')
testGlob('(.*)')
testGlob('!(.*)')

Current output:

.*
✗: foo
✗: foo/.bar
✓: .bar
✗: .foo/.bar

(.*)
✗: foo
✗: foo/.bar
✓: .bar
✗: .foo/.bar

!(.*)
✓: foo
✗: foo/.bar
✗: .bar
✗: .foo/.bar

The first two patterns match correctly, but ! appears to break the behavior of .*

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied JavaScript reproduction through picomatch's public entry point, then trace how negated extglobs are compiled and matched. Add regression coverage for the four listed paths and verify that !(.) is the exact inverse of ..

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.