From 4da8c626f78be18436752311e1f05f2661f499d8 Mon Sep 17 00:00:00 2001 From: Bettenbuk Zoltan <zoltan.bettenbuk@gmail.com> Date: Sun, 16 Dec 2018 20:59:17 +0100 Subject: [PATCH] Exclude static jitsi links from calendar fetch --- react/features/calendar-sync/functions.any.js | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/react/features/calendar-sync/functions.any.js b/react/features/calendar-sync/functions.any.js index 92b8c3483..fd8fbe298 100644 --- a/react/features/calendar-sync/functions.any.js +++ b/react/features/calendar-sync/functions.any.js @@ -96,6 +96,30 @@ export function _updateCalendarEntries(events: Array<Object>) { .slice(0, MAX_LIST_LENGTH))); } +/** + * Checks a string against a positive pattern and a negative pattern. Returns + * the string if it matches the positive pattern and doesn't provide any match + * against the negative pattern. Null otherwise. + * + * @param {string} str - The string to check. + * @param {string} positivePattern - The positive pattern. + * @param {string} negativePattern - The negative pattern. + * @returns {string} + */ +function _checkPattern(str, positivePattern, negativePattern) { + const positiveRegExp = new RegExp(positivePattern, 'gi'); + let positiveMatch; + + while ((positiveMatch = positiveRegExp.exec(str)) !== null) { + // $FlowFixMe + const url = positiveMatch[0]; + + if (!new RegExp(negativePattern, 'gi').exec(url)) { + return url; + } + } +} + /** * Updates the calendar entries in Redux when new list is received. * @@ -155,11 +179,9 @@ function _parseCalendarEntry(event, knownDomains) { function _getURLFromEvent(event, knownDomains) { const linkTerminatorPattern = '[^\\s<>$]'; const urlRegExp - = new RegExp( - `http(s)?://(${knownDomains.join('|')})/${linkTerminatorPattern}+`, - 'gi'); - const schemeRegExp - = new RegExp(`${APP_LINK_SCHEME}${linkTerminatorPattern}+`, 'gi'); + = `http(s)?://(${knownDomains.join('|')})/${linkTerminatorPattern}+`; + const schemeRegExp = `${APP_LINK_SCHEME}${linkTerminatorPattern}+`; + const excludePattern = '/static/'; const fieldsToSearch = [ event.title, event.url, @@ -170,10 +192,12 @@ function _getURLFromEvent(event, knownDomains) { for (const field of fieldsToSearch) { if (typeof field === 'string') { - const matches = urlRegExp.exec(field) || schemeRegExp.exec(field); + const match + = _checkPattern(field, urlRegExp, excludePattern) + || _checkPattern(field, schemeRegExp, excludePattern); - if (matches) { - const url = parseURIString(matches[0]); + if (match) { + const url = parseURIString(match); if (url) { return url.toString();