Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(filepattern): the pattern only matches filenames, not full paths #449

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Tieske
Copy link
Member

@Tieske Tieske commented Mar 14, 2023

Some underlying methods, traversing files in directories and/or recursive functions suffer from the same problem.

Some underlying methods, traversing files in directories and/or
recursive functions suffer from the same problem.
@Tieske
Copy link
Member Author

Tieske commented Mar 14, 2023

this function;

local function filemask(mask)
    mask = utils.escape(path.normcase(mask))
    return '^'..mask:gsub('%%%*','.*'):gsub('%%%?','.')..'$'
end

creates the pattern for matching. It has a start-anchor so the old code would only match if the pattern included "*".

eg. "*.lua would match "/some/path/myfile.lua".
But "my*.lua" would not match "/some/path/myfile.lua".

so instead of using ".*" and "." as patterns, we should probably change to "[^/\\]*" and "[^/\\]" .

See https://en.wikipedia.org/wiki/Glob_(programming), which explicitly names fnmatch as the common interface, so that clearly gives the intent of the function.

@Tieske
Copy link
Member Author

Tieske commented Mar 14, 2023

looking at python; https://docs.python.org/3/library/fnmatch.html it mentions "Note that the filename separator ('/' on Unix) is not special to this module."

Which seems consistent with the existing implementation, yet makes for a bad user experience imho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant