diff --git a/docshell/base/URIFixup.sys.mjs b/docshell/base/URIFixup.sys.mjs index a0f31181feef..8009b7065d02 100644 --- a/docshell/base/URIFixup.sys.mjs +++ b/docshell/base/URIFixup.sys.mjs @@ -925,8 +925,8 @@ function fileURIFixup(uriString) { path = uriString.replace(/\//g, "\\"); } } else { - // UNIX: Check if it starts with "/". - attemptFixup = uriString.startsWith("/"); + // UNIX: Check if it starts with "/" or "~". + attemptFixup = /^[~/]/.test(uriString); } if (attemptFixup) { try { diff --git a/docshell/test/unit/test_URIFixup_info.js b/docshell/test/unit/test_URIFixup_info.js index 89514cb00c0b..66d5ff9c5b03 100644 --- a/docshell/test/unit/test_URIFixup_info.js +++ b/docshell/test/unit/test_URIFixup_info.js @@ -802,6 +802,18 @@ if (AppConstants.platform == "win") { affectedByDNSForSingleWordHosts: true, }); } else { + const homeDir = Services.dirsvc.get("Home", Ci.nsIFile).path; + + testcases.push({ + input: "~", + fixedURI: `file://${homeDir}`, + protocolChange: true, + }); + testcases.push({ + input: "~/foo", + fixedURI: `file://${homeDir}/foo`, + protocolChange: true, + }); testcases.push({ input: "/some/file.txt", fixedURI: "file:///some/file.txt",