diff --git a/CHANGELOG.md b/CHANGELOG.md index 87c1d05..980f96e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ ambiguous situations. ## Unreleased +### Changed +- Use `/` instead of `\` as path separator for (regex) rules on Windows + ## 3.0.1 - 2021-06-01 ### Added diff --git a/PFERD/transformer.py b/PFERD/transformer.py index 83ffde4..ed123eb 100644 --- a/PFERD/transformer.py +++ b/PFERD/transformer.py @@ -10,7 +10,7 @@ from pathlib import PurePath from typing import Dict, Optional, Sequence, Union from .logging import log -from .utils import fmt_path +from .utils import fmt_path, str_path class Rule(ABC): @@ -116,7 +116,7 @@ class ReRule(Rule): self._right = right def transform(self, path: PurePath) -> Union[PurePath, bool]: - if match := re.fullmatch(self._left, str(path)): + if match := re.fullmatch(self._left, str_path(path)): if isinstance(self._right, bool): return self._right or path diff --git a/PFERD/utils.py b/PFERD/utils.py index 397feda..7c7b6f4 100644 --- a/PFERD/utils.py +++ b/PFERD/utils.py @@ -91,8 +91,14 @@ def url_set_query_params(url: str, params: Dict[str, str]) -> str: return result +def str_path(path: PurePath) -> str: + if not path.parts: + return "." + return "/".join(path.parts) + + def fmt_path(path: PurePath) -> str: - return repr(str(path)) + return repr(str_path(path)) def fmt_real_path(path: Path) -> str: