From 11bd76e99688a606d66825a47c46c559336b4c92 Mon Sep 17 00:00:00 2001 From: Vinny Diehl Date: Mon, 14 Aug 2023 07:45:56 +0000 Subject: [PATCH] Bug 93141 - Expand `~` to home directory when fixing up file URIs r=mak Differential Revision: https://phabricator.services.mozilla.com/D185562 --- docshell/base/URIFixup.sys.mjs | 4 ++-- docshell/test/unit/test_URIFixup_info.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) 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",