From b0f4ee4413ea77c154392f57b56e9e63edf5f704 Mon Sep 17 00:00:00 2001 From: Hannu Hartikainen Date: Tue, 1 Dec 2015 21:31:12 +0200 Subject: [PATCH] fix #688 and provide a unit test --- js/filters.js | 2 +- test/unit/filters.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/js/filters.js b/js/filters.js index 70f9341..46fa02e 100644 --- a/js/filters.js +++ b/js/filters.js @@ -120,7 +120,7 @@ weechat.filter('DOMfilter', ['$filter', '$sce', function($filter, $sce) { if (node === undefined || node === null) return; node = node.firstChild; while (node) { - var nextNode; + var nextNode = null; // do not recurse inside links if the filter would create a nested link if (!(createsAnchor && node.tagName === 'A')) { nextNode = process(node); diff --git a/test/unit/filters.js b/test/unit/filters.js index b1eedec..2b1358f 100644 --- a/test/unit/filters.js +++ b/test/unit/filters.js @@ -83,5 +83,13 @@ describe('Filters', function() { result = DOMfilterFilter(dom, 'number', 2).$$unwrapTrustedValue(); expect(result).toEqual(expected); })); + + it('should never lock up like in bug #688', inject(function(linkyFilter, DOMfilterFilter) { + var msg = '#crash http://google.com', + linked = linkyFilter(msg), + irclinked = DOMfilterFilter(linked, 'irclinky'); + // With the bug, the DOMfilterFilter call ends up in an infinite loop. + // I.e. if we ever got this far, the bug is fixed. + })); }); });