Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog/+user-dirs-backslash-line-end.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Drop a backslash before the line break that ends an unquoted ``user-dirs.dirs`` value instead of keeping it in the
folder name.
4 changes: 3 additions & 1 deletion src/platformdirs/unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ def _get_user_dirs_folder(key: str) -> str | None:
encoding=sys.getfilesystemencoding(), errors="surrogateescape", newline="\n"
) as stream:
for line in stream:
if (entry := _USER_DIRS_LINE.match(line.removesuffix("\n").removesuffix("\r"))) and entry["key"] == key:
# Drop a CR that ends the line but keep the LF, so a backslash before it is not taken as ending the file.
if (entry := _USER_DIRS_LINE.match(_LINE_END_CR.sub("", line))) and entry["key"] == key:
folder = _resolve_user_dirs_value(entry) or folder
except OSError: # a missing or unreadable file leaves the defaults in place
return None
Expand Down Expand Up @@ -455,6 +456,7 @@ def _in_own_runtime_dir(path: Path) -> bool:
)


_LINE_END_CR: Final[re.Pattern[str]] = re.compile(r"\r(?=\n?\Z)")
_VALUE_PATTERN: Final[re.Pattern[str]] = re.compile(r'\\([$`"\\])')
_BARE_VALUE_PATTERN: Final[re.Pattern[str]] = re.compile(r"\\(.)")

Expand Down
Loading