From ea62cbb120729eab2a14502102db81f98566793d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Hu=CC=88hne?= Date: Wed, 6 Nov 2024 18:32:52 +0100 Subject: [PATCH] Allow using `mailto:` links in e-mail buttons --- package.json | 4 ++-- .../EmailSettings/utils/formatUrl.spec.ts | 5 +++++ .../EmailEditor/EmailSettings/utils/formatUrl.ts | 5 +++++ yarn.lock | 16 ++++++++-------- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 2195f49222..36be4ad365 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,7 @@ "timezones-list": "^3.0.2", "tsconfig-paths": "^4.1.2", "unified": "^10.1.2", - "validator": "^13.6.0", + "validator": "^13.12.0", "xlsx": "^0.18.5", "xlsx-js-style": "^1.2.0", "yaml": "^1.10.0", @@ -127,7 +127,7 @@ "@types/random-seed": "^0.3.3", "@types/react": "^18.0.18", "@types/react-dom": "^18.0.6", - "@types/validator": "^13.6.3", + "@types/validator": "^13.12.2", "@typescript-eslint/eslint-plugin": "^7.4.0", "@typescript-eslint/parser": "^7.4.0", "babel-loader": "^8.2.2", diff --git a/src/features/emails/components/EmailEditor/EmailSettings/utils/formatUrl.spec.ts b/src/features/emails/components/EmailEditor/EmailSettings/utils/formatUrl.spec.ts index 437fae652d..b0538ff588 100644 --- a/src/features/emails/components/EmailEditor/EmailSettings/utils/formatUrl.spec.ts +++ b/src/features/emails/components/EmailEditor/EmailSettings/utils/formatUrl.spec.ts @@ -15,4 +15,9 @@ describe('formatUrl()', () => { const formatted = formatUrl('Angela'); expect(formatted).toEqual(null); }); + + it('does nothing with a valid mailto: url', () => { + const formatted = formatUrl('mailto:test@example.org'); + expect(formatted).toEqual('mailto:test@example.org'); + }); }); diff --git a/src/features/emails/components/EmailEditor/EmailSettings/utils/formatUrl.ts b/src/features/emails/components/EmailEditor/EmailSettings/utils/formatUrl.ts index f3a42294ec..592820ff36 100644 --- a/src/features/emails/components/EmailEditor/EmailSettings/utils/formatUrl.ts +++ b/src/features/emails/components/EmailEditor/EmailSettings/utils/formatUrl.ts @@ -1,6 +1,11 @@ import isURL from 'validator/lib/isURL'; +import isMailtoURI from 'validator/lib/isMailtoURI'; export default function formatUrl(url: string): string | null { + if (isMailtoURI(url)) { + return url; + } + if (isURL(url, { require_protocol: true })) { return url; } diff --git a/yarn.lock b/yarn.lock index 77cb27b5ea..599d53cd94 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4746,10 +4746,10 @@ resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.8.tgz#7545ba4fc3c003d6c756f651f3bf163d8f0f29ba" integrity sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA== -"@types/validator@^13.6.3": - version "13.7.0" - resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.7.0.tgz#fa25263656d234473025c2d48249a900053c355a" - integrity sha512-+jBxVvXVuggZOrm04NR8z+5+bgoW4VZyLzUO+hmPPW1mVFL/HaitLAkizfv4yg9TbG8lkfHWVMQ11yDqrVVCzA== +"@types/validator@^13.12.2": + version "13.12.2" + resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.12.2.tgz#760329e756e18a4aab82fc502b51ebdfebbe49f5" + integrity sha512-6SlHBzUW8Jhf3liqrGGXyTJSIFe4nqlJ5A5KaMZ2l/vbM3Wh3KSybots/wfWVzNLK4D1NZluDlSQIbIEPx6oyA== "@types/webidl-conversions@*": version "7.0.3" @@ -15509,10 +15509,10 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" -validator@^13.6.0: - version "13.7.0" - resolved "https://registry.yarnpkg.com/validator/-/validator-13.7.0.tgz#4f9658ba13ba8f3d82ee881d3516489ea85c0857" - integrity sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw== +validator@^13.12.0: + version "13.12.0" + resolved "https://registry.yarnpkg.com/validator/-/validator-13.12.0.tgz#7d78e76ba85504da3fee4fd1922b385914d4b35f" + integrity sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg== vary@^1, vary@~1.1.2: version "1.1.2"