diff --git a/gitignorefile/__init__.py b/gitignorefile/__init__.py index bf880c1..4a721bf 100644 --- a/gitignorefile/__init__.py +++ b/gitignorefile/__init__.py @@ -82,7 +82,6 @@ def __init__(self, path): if isinstance(path, str): abs_path = os.path.abspath(path) self.__parts = tuple(_path_split(abs_path)) - print(self.__parts) self.__joined = abs_path self.__is_dir = None @@ -260,9 +259,6 @@ def match(self, rel_path, is_dir): return match and (not self.__directory_only or match.group(1) is not None or is_dir) -_seps_expr = re.escape(os.sep) -_non_sep_expr = f"[^{re.escape(os.sep)}]" - if os.altsep is not None: _all_seps_expr = f"[{re.escape(os.sep)}{re.escape(os.altsep)}]" _path_split = lambda path: re.split(_all_seps_expr, path) @@ -280,7 +276,7 @@ def _fnmatch_pathname_to_regexp(pattern, directory_only): """ i, n = 0, len(pattern) - res = [f"(?:^|{_seps_expr})"] if pattern else [] # Empty name means no path fragment. + res = ["(?:^|/)"] if pattern else [] # Empty name means no path fragment. while i < n: c = pattern[i] i += 1 @@ -291,19 +287,16 @@ def _fnmatch_pathname_to_regexp(pattern, directory_only): res.append(".*") if pattern[i] == "/": i += 1 - res.append(f"{_seps_expr}?") + res.append("/?") else: - res.append(f"{_non_sep_expr}*") + res.append(f"[^/]*") except IndexError: - res.append(f"{_non_sep_expr}*") + res.append(f"[^/]*") elif c == "?": - res.append(_non_sep_expr) - - elif c == "/": - res.append(_seps_expr) + res.append("[^/]") elif c == "[": j = i @@ -329,9 +322,9 @@ def _fnmatch_pathname_to_regexp(pattern, directory_only): res.append(re.escape(c)) if directory_only: # In this case we are interested if there is something after slash. - res.append(f"({_seps_expr}.+)?$") + res.append(f"(/.+)?$") else: - res.append(f"(?:{_seps_expr}|$)") + res.append(f"(?:/|$)") return "".join(res)