mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Always use '/' as path separator for regex rules
Previously, regex-matching paths on windows would, in some cases, require four backslashes ('\\\\') to escape a single path separator. That's just too much. With this commit, regex transforms now use '/' instead of '\' as path separator, meaning rules can more easily be shared between platforms (although they are not guaranteed to be 100% compatible since on Windows, '\' is still recognized as a path separator). To make rules more intuitive to write, local relative paths are now also printed with '/' as path separator on Windows. Since Windows also accepts '/' as path separator, this change doesn't really affect other rules that parse their sides as paths.
This commit is contained in:
parent
31b6311e99
commit
fc31100a0f
@ -22,6 +22,9 @@ ambiguous situations.
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Use `/` instead of `\` as path separator for (regex) rules on Windows
|
||||||
|
|
||||||
## 3.0.1 - 2021-06-01
|
## 3.0.1 - 2021-06-01
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -10,7 +10,7 @@ from pathlib import PurePath
|
|||||||
from typing import Dict, Optional, Sequence, Union
|
from typing import Dict, Optional, Sequence, Union
|
||||||
|
|
||||||
from .logging import log
|
from .logging import log
|
||||||
from .utils import fmt_path
|
from .utils import fmt_path, str_path
|
||||||
|
|
||||||
|
|
||||||
class Rule(ABC):
|
class Rule(ABC):
|
||||||
@ -116,7 +116,7 @@ class ReRule(Rule):
|
|||||||
self._right = right
|
self._right = right
|
||||||
|
|
||||||
def transform(self, path: PurePath) -> Union[PurePath, bool]:
|
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):
|
if isinstance(self._right, bool):
|
||||||
return self._right or path
|
return self._right or path
|
||||||
|
|
||||||
|
@ -91,8 +91,14 @@ def url_set_query_params(url: str, params: Dict[str, str]) -> str:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def str_path(path: PurePath) -> str:
|
||||||
|
if not path.parts:
|
||||||
|
return "."
|
||||||
|
return "/".join(path.parts)
|
||||||
|
|
||||||
|
|
||||||
def fmt_path(path: PurePath) -> str:
|
def fmt_path(path: PurePath) -> str:
|
||||||
return repr(str(path))
|
return repr(str_path(path))
|
||||||
|
|
||||||
|
|
||||||
def fmt_real_path(path: Path) -> str:
|
def fmt_real_path(path: Path) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user