lib.Uri: Treat paths starting with "~" specially
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 3m50s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 3m51s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m50s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m10s
CI / Packaging test (push) Successful in 0s
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 3m50s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 3m51s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m50s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m10s
CI / Packaging test (push) Successful in 0s
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 <jan@janware.com>
This commit is contained in:
parent
2c38c8a144
commit
96409e50f7
1 changed files with 3 additions and 1 deletions
|
|
@ -17,6 +17,8 @@ class Uri:
|
||||||
self, scheme: bool, credentials: bool, secure: bool, path: bool
|
self, scheme: bool, credentials: bool, secure: bool, path: bool
|
||||||
) -> str:
|
) -> str:
|
||||||
ret = ''
|
ret = ''
|
||||||
|
if self.__p.path.startswith('~'):
|
||||||
|
return self.path
|
||||||
if scheme:
|
if scheme:
|
||||||
ret += f'{self.protocol}://'
|
ret += f'{self.protocol}://'
|
||||||
if credentials and self.username:
|
if credentials and self.username:
|
||||||
|
|
@ -62,7 +64,7 @@ class Uri:
|
||||||
@cached_property
|
@cached_property
|
||||||
def scheme(self) -> str:
|
def scheme(self) -> str:
|
||||||
ret = self.__p.scheme
|
ret = self.__p.scheme
|
||||||
if not ret:
|
if not ret and not self.__p.path.startswith('~'):
|
||||||
return 'file'
|
return 'file'
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue