From c7e8b65b6c3e0febe289a1282708bd3f8021bb46 Mon Sep 17 00:00:00 2001 From: gorhill Date: Fri, 8 Dec 2017 00:33:02 -0500 Subject: [PATCH] fix #3328 --- src/js/hntrie.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/js/hntrie.js b/src/js/hntrie.js index 7ba879c37..61c5c9e06 100644 --- a/src/js/hntrie.js +++ b/src/js/hntrie.js @@ -184,19 +184,13 @@ HNTrieBuilder.prototype.add = function(hn) { */ HNTrieBuilder.prototype.fromDomainOpt = function(hostnames) { - var len = hostnames.length, - beg = 0, end; - while ( beg < len ) { - end = hostnames.indexOf('|', beg); - if ( end === -1 ) { end = len; } - this.add(hostnames.slice(beg, end)); - beg = end + 1; - } - return this; + return this.fromIterable(hostnames.split('|')); }; HNTrieBuilder.prototype.fromIterable = function(hostnames) { - for ( var hn of hostnames ) { + // https://github.com/gorhill/uBlock/issues/3328 + // Must sort from shortest to longest. + for ( var hn of hostnames.sort(function(a,b){return a.length-b.length;}) ) { this.add(hn); } return this;