|
| 1 | +local glob = require 'glob' |
| 2 | + |
| 3 | +local function ignored(patterns, path) |
| 4 | + return glob.gitignore(patterns)(path) |
| 5 | +end |
| 6 | + |
| 7 | +-- #3458: a whitespace-only gitignore pattern must not match every path |
| 8 | +assert(ignored({ ' ' }, 'a.lua') == false) |
| 9 | +assert(ignored({ ' ' }, 'foo/bar.lua') == false) |
| 10 | +assert(ignored({ '\t' }, 'a.lua') == false) |
| 11 | +assert(ignored({ '' }, 'a.lua') == false) |
| 12 | + |
| 13 | +-- Real patterns in the same list still match; the blank line does not take over |
| 14 | +assert(ignored({ ' ', '*.log' }, 'a.lua') == false) |
| 15 | +assert(ignored({ ' ', '*.log' }, 'a.log') == true) |
| 16 | + |
| 17 | +-- Intentional match-all and ordinary names are unchanged |
| 18 | +assert(ignored({ '*' }, 'a.lua') == true) |
| 19 | +assert(ignored({ 'foo' }, 'foo') == true) |
| 20 | +assert(ignored({ 'foo' }, 'bar') == false) |
| 21 | + |
| 22 | +-- Quoted trailing space is a real pattern (gitignore spec), not a blank line |
| 23 | +assert(ignored({ '\\ ' }, 'a.lua') == false) |
| 24 | +assert(ignored({ '\\ ' }, ' ') == true) |
| 25 | + |
| 26 | +-- glob.glob shares the same matcher; empty patterns must not match everything |
| 27 | +assert(glob.glob({ ' ' })('a.lua') == false) |
| 28 | +assert(glob.glob({ ' ', 'foo' })('foo') == true) |
| 29 | +assert(glob.glob({ ' ', 'foo' })('bar') == false) |
| 30 | +assert(glob.glob({ '*' })('a.lua') == true) |
0 commit comments