diff --git a/js/background.js b/js/background.js index d05e22e..4bae54b 100644 --- a/js/background.js +++ b/js/background.js @@ -63,10 +63,11 @@ var uBOScope = { // jshint ignore:line dtpAssetKey: 'disconnect-tracking-protection', reAuthorityFromURI: /^(?:[^:\/?#]+:)?(\/\/[^\/?#]+)/, reCommonHostnameFromURL: /^https?:\/\/([0-9a-z_][0-9a-z._-]*[0-9a-z])\//, - reHostFromAuthority: /^(?:[^@]*@)?([0-9a-z._-]+)(?::\d*)?$/i, + reHostFromAuthority: /^(?:[^@]*@)?([^:]+)(?::\d*)?$/, reHostFromNakedAuthority: /^[0-9a-z._-]+[0-9a-z]$/i, reIPAddressNaive: /^\d+\.\d+\.\d+\.\d+$|^\[[\da-zA-Z:]+\]$/, reIPv6FromAuthority: /^(?:[^@]*@)?(\[[0-9a-f:]+\])(?::\d*)?$/i, + reMustNormalizeHostname: /[^0-9a-z._-]/, settings: { daysBefore: 30, heatmapHue: 0, diff --git a/js/start.js b/js/start.js index 938df64..f9fc85f 100644 --- a/js/start.js +++ b/js/start.js @@ -65,29 +65,27 @@ uBOScope.getDoY.dayCountLeap = [ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 30 uBOScope.hostnameFromURI = function(uri) { let matches = this.reCommonHostnameFromURL.exec(uri); - if ( matches ) { - return matches[1]; - } + if ( matches !== null ) { return matches[1]; } matches = this.reAuthorityFromURI.exec(uri); - if ( !matches ) { return ''; } + if ( matches === null ) { return ''; } const authority = matches[1].slice(2); // Assume very simple authority (most common case for µBlock) if ( this.reHostFromNakedAuthority.test(authority) ) { return authority.toLowerCase(); } matches = this.reHostFromAuthority.exec(authority); - if ( !matches ) { + if ( matches === null ) { matches = this.reIPv6FromAuthority.exec(authority); - if ( !matches ) { return ''; } + if ( matches === null ) { return ''; } } - // http://en.wikipedia.org/wiki/FQDN - // Also: - // - https://github.com/gorhill/uBlock/issues/1559 let hostname = matches[1]; while ( hostname.endsWith('.') ) { hostname = hostname.slice(0, -1); } - return hostname.toLowerCase(); + if ( this.reMustNormalizeHostname.test(hostname) ) { + hostname = punycode.toASCII(hostname.toLowerCase()); + } + return hostname; }; /******************************************************************************/