Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
fix handling of IDN for Firefox 55
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Sep 7, 2017
1 parent 56b4d3d commit c03a2d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 8 additions & 10 deletions js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/******************************************************************************/
Expand Down

0 comments on commit c03a2d4

Please sign in to comment.