Skip to content

Commit 861f19f

Browse files
committed
switch to posix, rather than str for performing search
1 parent e767745 commit 861f19f

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

gitignore_parser.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ def __repr__(self):
126126
def match(self, abs_path: Union[str, Path]):
127127
matched = False
128128
if self.base_path:
129-
rel_path = str(_normalize_path(abs_path).relative_to(self.base_path))
129+
rel_path = _normalize_path(abs_path).relative_to(self.base_path).as_posix()
130130
else:
131-
rel_path = str(_normalize_path(abs_path))
132-
# Path() strips the trailing whitespace on windows, so we need to
133-
# preserve it.
131+
rel_path = _normalize_path(abs_path).as_posix()
132+
# Path() strips the trailing following symbols on windows, so we need to
133+
# preserve it: ' ', '.'
134134
if sys.platform.startswith('win'):
135-
rel_path += ' ' * _count_trailing_whitespace(abs_path)
135+
rel_path += ' ' * _count_trailing_symbol(' ', abs_path)
136+
rel_path += '.' * _count_trailing_symbol('.', abs_path)
136137
# Path() strips the trailing slash, so we need to preserve it
137138
# in case of directory-only negation
138139
if self.negation and type(abs_path) == str and abs_path[-1] == '/':
@@ -225,11 +226,11 @@ def _normalize_path(path: Union[str, Path]) -> Path:
225226
return Path(abspath(path))
226227

227228

228-
def _count_trailing_whitespace(text: str) -> int:
229-
"""Count the number of trailing whitespace characters in a string."""
229+
def _count_trailing_symbol(symbol: str, text: str) -> int:
230+
"""Count the number of trailing characters in a string."""
230231
count = 0
231232
for char in reversed(str(text)):
232-
if char.isspace():
233+
if char == symbol:
233234
count += 1
234235
else:
235236
break

tests.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from gitignore_parser import parse_gitignore
66

7-
from unittest import TestCase, main
7+
from unittest import TestCase, main, SkipTest
88

99

1010
class Test(TestCase):
@@ -195,8 +195,12 @@ def test_symlink_to_another_directory(self):
195195
# Create a symlink to another directory.
196196
link = project_dir / 'link'
197197
target = another_dir / 'target'
198-
link.symlink_to(target)
199-
198+
199+
try:
200+
link.symlink_to(target)
201+
except OSError:
202+
e = "Current User does not have permissions to perform symlink/"
203+
raise SkipTest(e)
200204
# Check the intended behavior according to
201205
# https://git-scm.com/docs/gitignore#_notes:
202206
# Symbolic links are not followed and are matched as if they were regular

0 commit comments

Comments
 (0)