From 88af7e12a08a5a597151a015d74fca8e243060b7 Mon Sep 17 00:00:00 2001 From: David Byers <david.byers@liu.se> Date: Thu, 1 Apr 2021 16:09:29 +0200 Subject: [PATCH] Added docstrings, updated messages. --- shared/_locales/en/messages.json | 2 +- shared/_locales/sv/messages.json | 2 +- shared/patterns.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/shared/_locales/en/messages.json b/shared/_locales/en/messages.json index d2943ff..51cd374 100644 --- a/shared/_locales/en/messages.json +++ b/shared/_locales/en/messages.json @@ -1,6 +1,6 @@ { "extensionDescription": { - "message": "Correct the display and quoting of links mangled by Microsoft Defender for Office 365 Safe Links.", + "message": "Correct the display and quoting of links mangled by Microsoft Defender for Office 365 Safe Links or Barracuda Link Protection.", "description": "Description of the extension." }, diff --git a/shared/_locales/sv/messages.json b/shared/_locales/sv/messages.json index e33708e..0334a9b 100644 --- a/shared/_locales/sv/messages.json +++ b/shared/_locales/sv/messages.json @@ -1,6 +1,6 @@ { "extensionDescription": { - "message": "Korrigera visning och citering av länkar manglade av Microsoft Defender för Office 365 Safe Links.", + "message": "Korrigera visning och citering av länkar manglade av Microsoft Defender för Office 365 Safe Links eller Barracuda Link Protection.", "description": "Description of the extension." }, diff --git a/shared/patterns.js b/shared/patterns.js index a52e3c5..332d4f7 100644 --- a/shared/patterns.js +++ b/shared/patterns.js @@ -25,23 +25,52 @@ const safelinksPatterns = [ { + name: 'Microsoft Defender For Office 365 Safe Links', host: '*.safelinks.protection.outlook.com', path: '[?]url=([^&]+).*' }, { + name: 'Barracuda Link Protection', host: 'linkprotect.cudasvc.com', path: 'url[?]a=([^&]+).*' + }, + { + name: 'Proofpoint (v3)', + host: 'urldefense.com', + path: 'v3/_+([^_]+).*' } + // { + // name: 'Proofpoint (v2)', + // host: 'urldefense.proofpoint.com', + // path: 'v2/url[?]u=([^&]+).*', + // proc: (string) => string.replace('_', '/') + // } ]; + +/** + * Compute a list of url patterns from the link patterns. + * @returns {Array} - Array of patterns. + */ function computeSafelinksMatchPatterns() { return safelinksPatterns.map(({host, path}) => '*://' + host + '/*'); } + +/** + * Escape a hostname pattern for use in a regexp. + * @param {string} host - The host name pattern. + * @returns {string} A suitable regexp. + */ function escapeHostname(host) { return host.replace('.', '[.]').replace('*', '[^/]*') } + +/** + * Compute a regexp that matches all mangled links. + * @returns {RegExp} A regexp that matches all possible mangled links. + */ function computeSafelinksRegexp() { return new RegExp('(?:' + safelinksPatterns.map( @@ -51,4 +80,5 @@ function computeSafelinksRegexp() { 'gi'); } + const safelinksRegexp = computeSafelinksRegexp() -- GitLab