Explorar el Código

HUE-8155 [metastore] Improve link matching in the description

Johan Ahlen hace 7 años
padre
commit
55af7b875c
Se han modificado 1 ficheros con 6 adiciones y 2 borrados
  1. 6 2
      desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

+ 6 - 2
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -582,10 +582,14 @@
       self.contents = options.text;
       self.element.innerHTML = self.contents;
 
+      var linkRegex = /(?:(?:[a-z]+:\/\/)|www\.)[^\s\/]+(?:[.\/]\S+)*[^\s`!()\[\]{};:'".,<>?«»“”‘’]/ig;
+
       self.renderContents = function (contents) {
         if (options.linkify) {
-          return hueUtils.deXSS(contents.replace(/((?:(?:[a-z]+:\/\/)|www\.)[a-z0-9_%\-]+(?:[.\/][a-z0-9_%\-]+)*)/ig, '<a href="$1" target="_blank">$1</a>'));
-        };
+          return hueUtils.deXSS(contents.replace(linkRegex, function (val) {
+            return '<a href="' + (val.toLowerCase().indexOf('www') === 0 ? 'http://' + val : val) + '" target="_blank">' + val + '</a>';
+          }));
+        }
         return hueUtils.deXSS(contents);
       };