From 216f65355f96c60db055f2fc70c62202d22a9743 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Wed, 6 Nov 2019 14:41:36 +0800 Subject: [PATCH] refactor(external_link): relpace test() with includes() --- lib/plugins/filter/after_post_render/external_link.js | 4 ++-- lib/plugins/filter/after_render/external_link.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/plugins/filter/after_post_render/external_link.js b/lib/plugins/filter/after_post_render/external_link.js index 8a940c5d66..089efb9a75 100644 --- a/lib/plugins/filter/after_post_render/external_link.js +++ b/lib/plugins/filter/after_post_render/external_link.js @@ -48,9 +48,9 @@ function externalLinkFilter(data) { : [config.external_link.exclude]; data.content = data.content.replace(//gi, (str, hrefStr, href) => { - if (/target=/gi.test(str) || !isExternal(href, config)) return str; + if (str.includes('target=') || !isExternal(href, config)) return str; - if (/rel=/gi.test(str)) { + if (str.includes('rel=')) { str = str.replace(/rel="(.*?)"/gi, (relStr, rel) => { if (!rel.includes('noopenner')) relStr = relStr.replace(rel, `${rel} noopener`); return relStr; diff --git a/lib/plugins/filter/after_render/external_link.js b/lib/plugins/filter/after_render/external_link.js index 5ddbe333df..ecac70f51c 100644 --- a/lib/plugins/filter/after_render/external_link.js +++ b/lib/plugins/filter/after_render/external_link.js @@ -54,9 +54,9 @@ function externalLinkFilter(data) { : [config.external_link.exclude]; data = data.replace(//gi, (str, hrefStr, href) => { - if (/target=/gi.test(str) || !isExternal(href, config)) return str; + if (str.includes('target=') || !isExternal(href, config)) return str; - if (/rel=/gi.test(str)) { + if (str.includes('rel=')) { str = str.replace(/rel="(.*?)"/gi, (relStr, rel) => { if (!rel.includes('noopenner')) relStr = relStr.replace(rel, `${rel} noopener`); return relStr;