From 23833dbab048e0da74fb2f3c4405456ff6383adc Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Thu, 27 Jun 2024 23:38:43 +0200 Subject: [PATCH] Revert "convert entire words as urls or do nothing" --- src/js/filters.js | 34 ++++++++++++---------------------- test/unit/filters.js | 21 +++------------------ 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/src/js/filters.js b/src/js/filters.js index d7ebf66..6274c78 100644 --- a/src/js/filters.js +++ b/src/js/filters.js @@ -68,30 +68,20 @@ weechat.filter('conditionalLinkify', ['$filter', function($filter) { return text; } - - return text.replaceAll(/\S+/g, function (match, p2) { - const result = linkifyStr(match, { - className: '', - attributes: { - rel: 'noopener noreferrer' - }, - target: { - url: '_blank' - }, - validate: { - email: function () { - return false; //Do not linkify emails - } + return linkifyStr(text, { + className: '', + attributes: { + rel: 'noopener noreferrer' + }, + target: { + url: '_blank' + }, + validate: { + email: function () { + return false; //Do not linkify emails } - }); - - if (result.endsWith("")) { - return result; - } else { - return match } - - }); + }); }; }]); diff --git a/test/unit/filters.js b/test/unit/filters.js index d7820e8..6c09c77 100644 --- a/test/unit/filters.js +++ b/test/unit/filters.js @@ -21,30 +21,15 @@ describe('Filters', function() { var url = 'asdf https://a.example.com/wiki/asdf_qwer_(rivi%C3%A8re) Some text.', link = 'asdf https://a.example.com/wiki/asdf_qwer_(rivi%C3%A8re) Some text.', result = $filter('conditionalLinkify')(url); - expect(result).toEqual(link); + expect(result).toEqual(link); })); it('should not make emails into links', angular.mock.inject(function($filter) { var url = 'asdf@gmail.com', link = 'asdf@gmail.com', result = $filter('conditionalLinkify')(url); - expect(result).toEqual(link); + expect(result).toEqual(link); })); - - it('convert the entire words to links', angular.mock.inject(function($filter) { - var text = 'weechat.network.connection_timeout', - link = 'weechat.network.connection_timeout', - result = $filter('conditionalLinkify')(text); - expect(result).toEqual(link); - })); - - it('linkify parenthesis at the end of an url', angular.mock.inject(function($filter) { - var text = 'http://test.com/(test)', - link = 'http://test.com/(test)', - result = $filter('conditionalLinkify')(text); - expect(result).toEqual(link); - })); - }); describe('irclinky', function() { @@ -168,6 +153,6 @@ describe('Filters', function() { expect(codifyFilter('Weird`ness`')).toEqual('Weird`ness`'); })); - + }); });