Skip to content

Negation doesn't properly invert matching of patterns #148

@bhuber

Description

@bhuber

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 .*

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions