From fa54e8a61ef51096d6ca73a0393508356f782282 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Thu, 6 Jan 2022 11:23:44 -0800 Subject: [PATCH] Protocol filter: Support home path mapped to UNC share Co-authored-by: Scott Nonnenberg --- app/protocol_filter.ts | 8 +++++++- test/app/protocol_filter_test.js | 22 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/protocol_filter.ts b/app/protocol_filter.ts index 1391d6154..ec9ad3c9b 100644 --- a/app/protocol_filter.ts +++ b/app/protocol_filter.ts @@ -29,7 +29,13 @@ export function _urlToPath( options?: { isWindows: boolean } ): string { const decoded = decodeURIComponent(targetUrl); - const withoutScheme = decoded.slice(options?.isWindows ? 8 : 7); + + // We generally expect URLs to start with file:// or file:/// here, but for users with + // their home directory redirected to a UNC share, it will start with //. + const withoutScheme = decoded.startsWith('//') + ? decoded + : decoded.slice(options?.isWindows ? 8 : 7); + const withoutQuerystring = _eliminateAllAfterCharacter(withoutScheme, '?'); const withoutHash = _eliminateAllAfterCharacter(withoutQuerystring, '#'); diff --git a/test/app/protocol_filter_test.js b/test/app/protocol_filter_test.js index 2e6eea7f2..4e3a892b7 100644 --- a/test/app/protocol_filter_test.js +++ b/test/app/protocol_filter_test.js @@ -67,8 +67,24 @@ describe('Protocol Filter', () => { expect(actual).to.equal(expected); }); - // this seems to be the only way to get a relative path through Electron - it('handles SMB share path', () => { + it('handles UNC path', () => { + const path = '//share/path'; + const expected = '//share/path'; + + const actual = _urlToPath(path); + expect(actual).to.equal(expected); + }); + + it('handles UNC path on windows', () => { + const path = '//share/path'; + const expected = '//share/path'; + const isWindows = true; + + const actual = _urlToPath(path, { isWindows }); + expect(actual).to.equal(expected); + }); + + it('handles simple relative path', () => { const path = 'file://relative/path'; const expected = 'relative/path'; @@ -76,7 +92,7 @@ describe('Protocol Filter', () => { expect(actual).to.equal(expected); }); - it('handles SMB share path on windows', () => { + it('handles simple relative path', () => { const path = 'file://relative/path'; const expected = 'elative/path'; const isWindows = true;