Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
<!-- Add all new changes here. They will be moved under a version at release -->
* `FIX` A `.gitignore` line containing only whitespace no longer ignores the entire workspace [#3458](https://github.com/LuaLS/lua-language-server/issues/3458)
* `FIX` `need-check-nil` diagnostic is no longer reported on safe navigation access (e.g. `x?.field`, `f?.()`, `t?.[key]`), since the optional access itself already handles the nil check. Note that a non-safe access chained after a safe one (e.g. `x.upper()?.field`) still reports, because the safe access only protects its own result.

## 3.19.1
Expand Down
3 changes: 3 additions & 0 deletions script/glob/matcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ function mt:slash(_, state, index)
end

function mt:pattern(state)
if not state[1] then
return nil
end
if state.root then
local after = self:exp(state, 1)
if after then
Expand Down
30 changes: 30 additions & 0 deletions test/basic/gitignore.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
local glob = require 'glob'

local function ignored(patterns, path)
return glob.gitignore(patterns)(path)
end

-- #3458: a whitespace-only gitignore pattern must not match every path
assert(ignored({ ' ' }, 'a.lua') == false)
assert(ignored({ ' ' }, 'foo/bar.lua') == false)
assert(ignored({ '\t' }, 'a.lua') == false)
assert(ignored({ '' }, 'a.lua') == false)

-- Real patterns in the same list still match; the blank line does not take over
assert(ignored({ ' ', '*.log' }, 'a.lua') == false)
assert(ignored({ ' ', '*.log' }, 'a.log') == true)

-- Intentional match-all and ordinary names are unchanged
assert(ignored({ '*' }, 'a.lua') == true)
assert(ignored({ 'foo' }, 'foo') == true)
assert(ignored({ 'foo' }, 'bar') == false)

-- Quoted trailing space is a real pattern (gitignore spec), not a blank line
assert(ignored({ '\\ ' }, 'a.lua') == false)
assert(ignored({ '\\ ' }, ' ') == true)

-- glob.glob shares the same matcher; empty patterns must not match everything
assert(glob.glob({ ' ' })('a.lua') == false)
assert(glob.glob({ ' ', 'foo' })('foo') == true)
assert(glob.glob({ ' ', 'foo' })('bar') == false)
assert(glob.glob({ '*' })('a.lua') == true)
1 change: 1 addition & 0 deletions test/basic/init.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
require 'basic.textmerger'
require 'basic.filewatch'
require 'basic.gitignore'
Loading