From 4a07482d46f7f93a44b649f35a9180ec3997718b Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 23 Mar 2015 10:40:03 -0400 Subject: [PATCH] cosmetic filtering: support unicode hostnames (#498) --- src/js/cosmetic-filtering.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index 8514112d8..d047af154 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -20,7 +20,7 @@ */ /* jshint bitwise: false */ -/* global µBlock */ +/* global punycode, µBlock */ /******************************************************************************/ @@ -514,6 +514,8 @@ var FilterContainer = function() { this.selectorCacheAgeMax = 20 * 60 * 1000; // 20 minutes this.selectorCacheCountMin = 10; this.selectorCacheTimer = null; + this.reHasUnicode = /[^\x00-\x7F]/; + this.punycode = punycode; this.reset(); }; @@ -719,6 +721,13 @@ FilterContainer.prototype.compileHostnameSelector = function(hostname, parsed, o hostname = hostname.slice(1); unhide ^= 1; } + + // punycode if needed + if ( this.reHasUnicode.test(hostname) ) { + //console.debug('µBlock.cosmeticFilteringEngine/FilterContainer.compileHostnameSelector> punycoding:', hostname); + hostname = this.punycode.toASCII(hostname); + } + // https://github.com/gorhill/uBlock/issues/188 // If not a real domain as per PSL, assign a synthetic one var hash;