From 96409e50f798d5a51b04caf8b517ef9ae47ef51d Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 7 Jul 2026 15:42:10 +0200 Subject: [PATCH] lib.Uri: Treat paths starting with "~" specially An Uri instance constructed from "~/some/path" returns "file://~/some/path" as the .full property, i.e. with the "~" in the authority part. That's not accurate and doesn't make the intended sense in an URL context, see RFC 8089: Common UNIX shells such as the Bourne-Again SHell (bash) and Z SHell (zsh) provide a function known as "tilde expansion" [Bash-Tilde] or "filename expansion" [Zsh-Tilde], where a path that begins with a tilde character "~" can be expanded out to a special directory name. No such facility exists using the file URI scheme; a tilde in a file URI is always just a tilde. The "fix" introduced by this commit makes .full return the path without file:// prepended. That's conservative. It could also chose to expand the tilde, which is arguably cleaner. To be introduced by a later change after this commit has seen more coverage. Signed-off-by: Jan Lindemann --- src/python/jw/pkg/lib/Uri.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/python/jw/pkg/lib/Uri.py b/src/python/jw/pkg/lib/Uri.py index fa48245d..d75f2c92 100644 --- a/src/python/jw/pkg/lib/Uri.py +++ b/src/python/jw/pkg/lib/Uri.py @@ -17,6 +17,8 @@ class Uri: self, scheme: bool, credentials: bool, secure: bool, path: bool ) -> str: ret = '' + if self.__p.path.startswith('~'): + return self.path if scheme: ret += f'{self.protocol}://' if credentials and self.username: @@ -62,7 +64,7 @@ class Uri: @cached_property def scheme(self) -> str: ret = self.__p.scheme - if not ret: + if not ret and not self.__p.path.startswith('~'): return 'file' return ret -- 2.55.0