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 Sep 14, 2021
1 parent 83fedf6 commit db09e81
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ class QuietLevels(object):
class GlobMatch(object):
def __init__(self, pattern):
if pattern:
# Pattern might be a list of comma-delimited strings
self.pattern_list = ','.join(pattern).split(',')
# We remove trailing path separators from each pattern
# because shell completion might add a trailing separator
# '/' after directory names
self.pattern_list = [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 db09e81

Please sign in to comment.