Skip to content

Commit

Permalink
Remove trailing system path separator from pattern
Browse files Browse the repository at this point in the history
Shell completion often adds a separator '/' after directory names.
Because os.walk() return paths without a trailing separator, we have
to remove trailing separators from patterns to ensure a proper match.

Granted, we could attempt to remove the trailing separator '/' only
from "directory patterns", not from "file patterns", but patterns are
currently just patterns - we do not distinguish between "file patterns"
and "directory patterns". A future improvment could be to interpret
a pattern with a trailing "/" as "directory pattern", but then how
would we define a "file pattern"? It's probably better to find a
different mechanism and keep discarding the trailing separator from
patterns.
  • Loading branch information
DimitriPapadopoulos committed Mar 17, 2023
1 parent a239c80 commit 2ffc65f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,14 @@ class GlobMatch:
def __init__(self, pattern: Optional[str]) -> None:
self.pattern_list: Optional[List[str]]
if pattern:
# Pattern might be a list of comma-delimited strings
self.pattern_list = ",".join(pattern).split(",")
self.pattern_list = [
# We remove trailing path separators from each pattern
# because shell completion might add a trailing separator
# '/' after directory names
p.rstrip(os.path.sep)
# Pattern might be a list of comma-separated patterns
for p in ",".join(pattern).split(",")
]
else:
self.pattern_list = None

Expand Down

0 comments on commit 2ffc65f

Please sign in to comment.