-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix localpath handling for file-URLs on different OS, especially on Windows #7206
Fix localpath handling for file-URLs on different OS, especially on Windows #7206
Conversation
This commit changes the semantics of RI.localpath to return a path that is OS-specific, i.e. can be used to access a local file
This commit introduces code to interpret the path component of a URL correctly as local path, especially to detect the drive-letter in Windows. This is different from interpreting a non-URL path as local path.
Codecov ReportBase: 88.89% // Head: 88.48% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## maint #7206 +/- ##
==========================================
- Coverage 88.89% 88.48% -0.42%
==========================================
Files 355 355
Lines 46674 46686 +12
Branches 6351 0 -6351
==========================================
- Hits 41493 41310 -183
- Misses 5166 5376 +210
+ Partials 15 0 -15
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Thx for attacking this, @christian-monch ! Just in case you are looking for more related stuff to iron out: There's |
Will take a look at it |
Ok, cleaned up, all green - thank you @christian-monch! |
PR released in |
Fixes #7186
The current code base treats the
path
component offile
-URLs not according to the conventions described in the relevant standard, i.e. RFC8089 in Appendix D.2 and Appendix E.2 (funnily enough Append E.2 defines some "nonstandard techniques for interacting with DOS- or Windows-like file paths and URIs").As @mih pointed out, there is support for the conventions described in RFC8089 Appendix D.2 and RFC8089 Appendix E.2 in python, implemented in
nturl2path
, which is transparently used inurllib.request.url2pathname
on Windows systems.This PR uses
urllib.request.url2pathname
to convert the path of a file-URL to a local path. This changes the behavior ofRI.localpath
if anRI
is an instance ofURL
, and the URL-scheme isfile
, In this caselocalpath
will return a result fromurllib.request.url2pathname
. This means for example that the following holds:RI('file:/c:/Windows').localpath == '/c:/Windows'
RI('file:/c:/Windows').localpath == 'C:\\Windows'
Note that the drive letter is converted to a canonical "upper case" representation.