You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2022/03/21 20:26:52 UTC

[camel-website] branch main updated: refactor: escapeAutoLinks utility

This is an automated email from the ASF dual-hosted git repository.

zregvart pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-website.git


The following commit(s) were added to refs/heads/main by this push:
     new 81dae36  refactor: escapeAutoLinks utility
81dae36 is described below

commit 81dae36955704f533ecc5c3e0d852562abd41acf
Author: Zoran Regvart <zo...@regvart.com>
AuthorDate: Mon Mar 21 21:26:43 2022 +0100

    refactor: escapeAutoLinks utility
    
    Cleanup a bit, allow text that starts with URL/email and convert to
    string as needed not to require chaining `valueAsString`.
---
 util/jsonpath-util.js | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/util/jsonpath-util.js b/util/jsonpath-util.js
index 901730e..b558324 100644
--- a/util/jsonpath-util.js
+++ b/util/jsonpath-util.js
@@ -62,10 +62,13 @@ module.exports = {
   },
 
   escapeAutoLinks: (text) => {
-    return text ? text
-      .replaceAll(/ (http|https|ftp|irc|mailto|file):\/\//g, ' \\$1://')
-      .replaceAll(/ (\b[\w\.\/\-\+]+@[\w\.\/\-]+\b)/g, ' \\$1')
-      : text
+    if (typeof text === 'undefined' || text === null) {
+      return text
+    }
+
+    return `${text}`
+      .replace(/(^|\w)(http|https|ftp|irc|mailto|file):\/\//g, '$1\\$2://')
+      .replace(/(^|\w)(\b[\w\.\/\-\+]+@[\w\.\/\-]+\b)/g, ' $1\\$2//')
   },
 
   extractSBName: (resourceid) => {