diff --git a/index.js b/index.js index d356573..b6371ca 100644 --- a/index.js +++ b/index.js @@ -191,18 +191,27 @@ const REPLACERS = [ : '\\/.+' ], - // intermediate wildcards + // normal intermediate wildcards [ // Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.*/' -> go - // 'abc.*' -> skip this rule - /(^|[^\\]+)\\\*(?=.+)/g, + // 'abc.*' -> skip this rule, + // coz trailing single wildcard will be handed by [trailing wildcard] + /(^|[^\\]+)(\\\*)+(?=.+)/g, // '*.js' matches '.js' // '*.js' doesn't match 'abc' - (_, p1) => `${p1}[^\\/]*` + (_, p1, p2) => { + // 1. + // > An asterisk "*" matches anything except a slash. + // 2. + // > Other consecutive asterisks are considered regular asterisks + // > and will match according to the previous rules. + const unescaped = p2.replace(/\\\*/g, '[^\\/]*') + return p1 + unescaped + } ], [ diff --git a/package.json b/package.json index b730811..d064bde 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ignore", - "version": "5.2.2", + "version": "5.2.3", "description": "Ignore is a manager and filter for .gitignore rules, the one used by eslint, gitbook and many others.", "files": [ "legacy.js", diff --git a/test/fixtures/cases.js b/test/fixtures/cases.js index bcd4b14..b859ecf 100644 --- a/test/fixtures/cases.js +++ b/test/fixtures/cases.js @@ -51,8 +51,7 @@ const cases = [ 'baz': 1, 'ba/z': 0, 'baaaaaaz': 1 - }, - true + } ], [ '#76 (invalid), comments with no heading whitespace',