From 6b266b78150ca8617ba248cca19325d003524ac6 Mon Sep 17 00:00:00 2001 From: Ronan Jouchet Date: Thu, 25 Feb 2021 18:48:00 -0500 Subject: [PATCH] (Attempt to) get rid of deprecated app dep `wurl` This one may be problematic, as it used to do TLD stuff: https://github.com/websanova/node-url/blob/7982a613bc/wurl.js#L4 So, the new WHATWG-URL-based implementation will consider `asana.com` to be "external" to `app.asana.com`, contrarily to before. Given the nature of Nativefier, I think it's actually what to expect, that in this case your "out of the app", and in e.g. asana landing's page, which you'd expect to see in your browser. Let's see if users disagree with that. --- app/package.json | 3 +-- app/src/helpers/helpers.ts | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/package.json b/app/package.json index 8535be1..0b18525 100644 --- a/app/package.json +++ b/app/package.json @@ -16,8 +16,7 @@ "electron-dl": "^3.1.0", "electron-squirrel-startup": "^1.0.0", "electron-window-state": "^5.0.3", - "source-map-support": "^0.5.19", - "wurl": "^2.5.4" + "source-map-support": "^0.5.19" }, "devDependencies": { "electron": "^11.3.0" diff --git a/app/src/helpers/helpers.ts b/app/src/helpers/helpers.ts index 99cdfc4..3eaa233 100644 --- a/app/src/helpers/helpers.ts +++ b/app/src/helpers/helpers.ts @@ -3,7 +3,6 @@ import * as os from 'os'; import * as path from 'path'; import { BrowserWindow } from 'electron'; -import wurl from 'wurl'; const INJECT_CSS_PATH = path.join(__dirname, '..', 'inject/inject.css'); @@ -33,9 +32,19 @@ export function linkIsInternal( return regex.test(newUrl); } - const currentDomain = wurl('domain', currentUrl); - const newDomain = wurl('domain', newUrl); - return currentDomain === newDomain; + try { + const currentDomain = new URL(currentUrl).hostname; + const newDomain = new URL(newUrl).hostname; + return currentDomain === newDomain; + } catch (err) { + console.warn( + 'Failed to parse domains as determining if link is internal. From:', + currentUrl, + 'To:', + newUrl, + ); + return false; + } } export function shouldInjectCss(): boolean {