From f7f2d0beec56929100f09dba7f47280f878d3d4d Mon Sep 17 00:00:00 2001 From: Anshuman Kumar Date: Fri, 30 Dec 2022 09:42:08 +0530 Subject: [PATCH] Update regex to find a match and replace if present --- inc/commons.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/inc/commons.js b/inc/commons.js index 14c4fc6..b005293 100644 --- a/inc/commons.js +++ b/inc/commons.js @@ -257,8 +257,14 @@ module.exports = function(request, fs) { return str if(typeof(user_preferences.domain_youtube) != 'undefined') - if(user_preferences.domain_youtube) - str = str.replace(youtubeRegex, protocol + user_preferences.domain_youtube) + if(user_preferences.domain_youtube){ + if (youtubeRegex.test(str)){ + str = str.replace(youtubeRegex, protocol + user_preferences.domain_youtube) + } else { + youtubeRegex = /(https?:\/\/)([A-z.]+\.)?youtu(be\.com|\.be)(?=.+)/gm; + str = str.replace(youtubeRegex, protocol + user_preferences.domain_youtube) + } + } if(typeof(user_preferences.domain_twitter) != 'undefined') if(user_preferences.domain_twitter){ @@ -266,7 +272,8 @@ module.exports = function(request, fs) { str = str.replace(twitterRegex, protocol + user_preferences.domain_twitter) } else { - str = str.replace('https://twitter.com',protocol + user_preferences.domain_twitter) + twitterRegex = /(https?:\/\/)(www\.)?twitter\.com(?=.)/gm; + str = str.replace(twitterRegex, protocol + user_preferences.domain_twitter) } }