OS.Path shim: Add Windows version of fromFileURI() from Fx102
Some checks failed
CI / Build, Upload, Test (push) Has been cancelled

Should fix #4588 for real
This commit is contained in:
Dan Stillman 2024-08-20 02:50:51 -04:00
parent dba666b990
commit 182bfb9a38

View file

@ -286,6 +286,28 @@ export let OS = {
},
fromFileURI: function (uri) {
if (Services.appinfo.OS == "WINNT") {
let url = new URL(uri);
if (url.protocol != "file:") {
throw new Error("fromFileURI expects a file URI");
}
// strip leading slash, since Windows paths don't start with one
uri = url.pathname.substr(1);
let path = decodeURI(uri);
// decode a few characters where URL's parsing is overzealous
path = path.replace(/%(3b|3f|23)/gi, match => decodeURIComponent(match));
path = this.normalize(path);
// this.normalize() does not remove the trailing slash if the path
// component is a drive letter. eg. 'C:\'' will not get normalized.
if (path.endsWith(":\\")) {
path = path.substr(0, path.length - 1);
}
return this.normalize(path);
}
let url = new URL(uri);
if (url.protocol != "file:") {
throw new Error("fromFileURI expects a file URI");