reviewboard: fix the comment linking regex (bug 1403352) r=glob
authorSteven MacLeod <steven@smacleod.ca>
Tue, 26 Sep 2017 17:58:14 -0400
changeset 75 f3d30cc0312ed6947f7bd625f5ff75680a5be17a
parent 74 f8309a35ae8e6e99844c03a11df91d5bdb66a7c3
child 76 c7129035a1d77d8c99f1bab47b6c46dc3e8b8b16
push id43
push userbjones@mozilla.com
push dateWed, 27 Sep 2017 04:29:54 +0000
reviewersglob
bugs1403352
reviewboard: fix the comment linking regex (bug 1403352) r=glob
reviewboard/reviewboard/static/rb/js/utils/linkifyUtils.js
reviewboard/reviewboard/static/rb/js/utils/tests/linkifyUtilsTests.js
--- a/reviewboard/reviewboard/static/rb/js/utils/linkifyUtils.js
+++ b/reviewboard/reviewboard/static/rb/js/utils/linkifyUtils.js
@@ -1,13 +1,28 @@
 RB.LinkifyUtils = {
+    URL_RE: new RegExp(
+        '\\b((' + [
+            'https://',
+            'http://',
+            'ftp://',
+            'ftps://',
+            'gopher://',
+            'mailto:',
+            'news:',
+            'sms:'
+        ].join('|') +
+        ')[\\-A-Za-z0-9+&@#\/%?=~_()|!:,.;]*([\\-A-Za-z0-9+@#\/%=~_();|]|))',
+        'g'
+    ),
+
     /* Linkify all URLs. */
     linkifyURLs: function(text) {
         return text.replace(
-            /\b([a-z]+:\/\/[\-A-Za-z0-9+&@#\/%?=~_()|!:,.;]*([\-A-Za-z0-9+@#\/%=~_();|]|))/g,
+            RB.LinkifyUtils.URL_RE,
             function(url) {
                 /*
                  * We might catch an entity at the end of the URL. This is hard
                  * to avoid, since we can't rely on advanced RegExp techniques
                  * in all browsers. So, we'll now search for it and prevent it
                  * from being part of the URL if it exists. However, a URL with
                  * an open bracket will not have its close bracket removed. This
                  * was a modification to the original bug fix.
--- a/reviewboard/reviewboard/static/rb/js/utils/tests/linkifyUtilsTests.js
+++ b/reviewboard/reviewboard/static/rb/js/utils/tests/linkifyUtilsTests.js
@@ -48,28 +48,74 @@ suite('rb/utils/linkifyUtils', function(
             RB.LinkifyUtils.linkifyChildren($el[0]);
 
             expect($el.html()).toBe('<pre>/r/123</pre>');
         });
     });
 
     describe('linkifyText', function() {
         describe('URLs', function() {
-            it('http-based URLs', function() {
+            it('http://', function() {
                 expect(RB.LinkifyUtils.linkifyText('http://example.com')).toBe(
                        '<a target="_blank" href="http://example.com">' +
                        'http://example.com</a>');
             });
 
-            it('https-based URLs', function() {
+            it('https://', function() {
                 expect(RB.LinkifyUtils.linkifyText('https://example.com')).toBe(
                        '<a target="_blank" href="https://example.com">' +
                        'https://example.com</a>');
             });
 
+            it('ftp://', function() {
+                expect(RB.LinkifyUtils.linkifyText('ftp://example.com')).toBe(
+                       '<a target="_blank" href="ftp://example.com">' +
+                       'ftp://example.com</a>');
+            });
+
+            it('ftps://', function() {
+                expect(RB.LinkifyUtils.linkifyText('ftps://example.com')).toBe(
+                       '<a target="_blank" href="ftps://example.com">' +
+                       'ftps://example.com</a>');
+            });
+
+            it('gopher://', function() {
+                expect(RB.LinkifyUtils.linkifyText('gopher://example.com')).toBe(
+                       '<a target="_blank" href="gopher://example.com">' +
+                       'gopher://example.com</a>');
+            });
+
+            it('mailto:', function() {
+                expect(RB.LinkifyUtils.linkifyText('mailto:user@example.com'))
+                    .toBe('<a target="_blank" href="mailto:user@example.com">' +
+                          'mailto:user@example.com</a>');
+            });
+
+            it('news:', function() {
+                expect(RB.LinkifyUtils.linkifyText('news:example.com'))
+                    .toBe('<a target="_blank" href="news:example.com">' +
+                          'news:example.com</a>');
+            });
+
+            it('sms:', function() {
+                expect(RB.LinkifyUtils.linkifyText('sms:example.com'))
+                    .toBe('<a target="_blank" href="sms:example.com">' +
+                          'sms:example.com</a>');
+            });
+
+            it('javascript: (unlinked)', function() {
+                expect(RB.LinkifyUtils.linkifyText('javascript:test'))
+                    .toBe('javascript:test');
+            });
+
+            it('javascript:// (unlinked)', function() {
+                expect(RB.LinkifyUtils.linkifyText('javascript://test'))
+                    .toBe('javascript://test');
+            });
+
             it('Trailing slashes', function() {
                 expect(RB.LinkifyUtils.linkifyText('http://example.com/foo/')).toBe(
                        '<a target="_blank" href="http://example.com/foo/">' +
                        'http://example.com/foo/</a>');
             });
 
             it('Anchors', function() {
                 expect(RB.LinkifyUtils.linkifyText('http://example.com/#my-anchor')).toBe(