Skip to content
This repository was archived by the owner on Nov 15, 2017. It is now read-only.

Commit bdf446e

Browse files
committed
this fixes #165
1 parent 27063ed commit bdf446e

File tree

4 files changed

+59
-70
lines changed

4 files changed

+59
-70
lines changed

js/httpsb.js

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ HTTPSB.domainScopeKeyFromURL = function(url) {
5353
if ( domain === '' ) {
5454
domain = hostname;
5555
}
56-
return scheme + '://*.' + domain;
56+
return '*.' + domain;
5757
};
5858

5959
HTTPSB.siteScopeKeyFromURL = function(url) {
60-
return uriTools.rootURLFromURI(url);
60+
return uriTools.hostnameFromURI(url);
6161
};
6262

6363
/******************************************************************************/
@@ -67,11 +67,11 @@ HTTPSB.isGlobalScopeKey = function(scopeKey) {
6767
};
6868

6969
HTTPSB.isDomainScopeKey = function(scopeKey) {
70-
return (/^https?:\/\/[*]/).test(scopeKey);
70+
return scopeKey.indexOf('*.') === 0;
7171
};
7272

7373
HTTPSB.isSiteScopeKey = function(scopeKey) {
74-
return (/^https?:\/\/[^*]/).test(scopeKey);
74+
return scopeKey.charAt(0) !== '*';
7575
};
7676

7777
HTTPSB.isValidScopeKey = function(scopeKey) {
@@ -87,19 +87,10 @@ HTTPSB.isValidScopeKey = function(scopeKey) {
8787
// global scope to take effect.
8888

8989
HTTPSB.createTemporaryGlobalScope = function(url) {
90-
var scopeKey;
91-
scopeKey = this.siteScopeKeyFromURL(url);
90+
var scopeKey = this.siteScopeKeyFromURL(url);
9291
this.removeTemporaryScopeFromScopeKey(scopeKey);
93-
if ( scopeKey.indexOf('https:') === 0 ) {
94-
scopeKey = 'http:' + scopeKey.slice(6);
95-
this.removeTemporaryScopeFromScopeKey(scopeKey);
96-
}
9792
scopeKey = this.domainScopeKeyFromURL(url);
9893
this.removeTemporaryScopeFromScopeKey(scopeKey);
99-
if ( scopeKey.indexOf('https:') === 0 ) {
100-
scopeKey = 'http:' + scopeKey.slice(6);
101-
this.removeTemporaryScopeFromScopeKey(scopeKey);
102-
}
10394
};
10495

10596
HTTPSB.createPermanentGlobalScope = function(url) {
@@ -109,22 +100,10 @@ HTTPSB.createPermanentGlobalScope = function(url) {
109100
if ( this.removePermanentScopeFromScopeKey(scopeKey) ) {
110101
changed = true;
111102
}
112-
if ( scopeKey.indexOf('https:') === 0 ) {
113-
scopeKey = 'http:' + scopeKey.slice(6);
114-
if ( this.removePermanentScopeFromScopeKey(scopeKey) ) {
115-
changed = true;
116-
}
117-
}
118103
scopeKey = this.domainScopeKeyFromURL(url);
119104
if ( this.removePermanentScopeFromScopeKey(scopeKey) ) {
120105
changed = true;
121106
}
122-
if ( scopeKey.indexOf('https:') === 0 ) {
123-
scopeKey = 'http:' + scopeKey.slice(6);
124-
if ( this.removePermanentScopeFromScopeKey(scopeKey) ) {
125-
changed = true;
126-
}
127-
}
128107
if ( changed ) {
129108
this.savePermissions();
130109
}
@@ -149,10 +128,6 @@ HTTPSB.createTemporaryDomainScope = function(url) {
149128
// Remove potentially occulting site scope.
150129
scopeKey = this.siteScopeKeyFromURL(url);
151130
this.removeTemporaryScopeFromScopeKey(scopeKey);
152-
if ( scopeKey.indexOf('https:') === 0 ) {
153-
scopeKey = 'http:' + scopeKey.slice(6);
154-
this.removeTemporaryScopeFromScopeKey(scopeKey);
155-
}
156131
};
157132

158133
HTTPSB.createPermanentDomainScope = function(url) {
@@ -171,12 +146,6 @@ HTTPSB.createPermanentDomainScope = function(url) {
171146
if ( this.removePermanentScopeFromScopeKey(scopeKey) ) {
172147
changed = true;
173148
}
174-
if ( scopeKey.indexOf('https:') === 0 ) {
175-
scopeKey = 'http:' + scopeKey.slice(6);
176-
if ( this.removePermanentScopeFromScopeKey(scopeKey) ) {
177-
changed = true;
178-
}
179-
}
180149

181150
if ( changed ) {
182151
this.savePermissions();
@@ -573,7 +542,7 @@ HTTPSB.turnOn = function() {
573542
chrome.contentSettings.javascript.clear({});
574543

575544
// rhill 2013-12-07:
576-
// Tell Chromium to all javascript: HTTPSB will control whether
545+
// Tell Chromium to allow all javascript: HTTPSB will control whether
577546
// javascript execute through `Content-Policy-Directive` and webRequest.
578547
// https://github.com/gorhill/httpswitchboard/issues/74
579548
chrome.contentSettings.javascript.set({

js/lists.js

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ PermissionList.prototype.assign = function(other) {
158158
}
159159
};
160160

161+
/******************************************************************************/
162+
163+
PermissionList.prototype.add = function(other) {
164+
for ( var kother in other.list ) {
165+
if ( other.list.hasOwnProperty(kother) && !this.list[kother] ) {
166+
this.list[kother] = true;
167+
this.count++;
168+
}
169+
}
170+
};
171+
161172
/******************************************************************************/
162173
/******************************************************************************/
163174

@@ -193,6 +204,14 @@ PermissionScope.prototype.assign = function(other) {
193204

194205
/******************************************************************************/
195206

207+
PermissionScope.prototype.add = function(other) {
208+
this.white.add(other.white);
209+
this.black.add(other.black);
210+
this.gray.add(other.gray);
211+
};
212+
213+
/******************************************************************************/
214+
196215
// This is the heart of HTTP Switchboard:
197216
//
198217
// Check whether something is white or blacklisted, direct or indirectly.
@@ -483,6 +502,26 @@ PermissionScopes.prototype.fromString = function(s) {
483502
scope.fromString(scopeBin.scopeStr);
484503
this.scopes[scopeBin.scopeKey] = scope;
485504
}
505+
// rhill 2014-01-27: Remove scheme from scopes and merge resulting scope
506+
// duplicates if any.
507+
// https://github.com/gorhill/httpswitchboard/issues/165
508+
// TODO: Remove once all users are beyond v0.7.9.0
509+
var oldScopeKey, newScopeKey;
510+
for ( var oldScopeKey in this.scopes ) {
511+
if ( !this.scopes.hasOwnProperty(oldScopeKey) ) {
512+
continue;
513+
}
514+
newScopeKey = oldScopeKey.replace(/^https?:\/\//, '');
515+
if ( newScopeKey === oldScopeKey ) {
516+
continue;
517+
}
518+
if ( this.scopes[newScopeKey] ) {
519+
this.scopes[newScopeKey].add(this.scopes[oldScopeKey]);
520+
} else {
521+
this.scopes[newScopeKey] = this.scopes[oldScopeKey];
522+
}
523+
delete this.scopes[oldScopeKey];
524+
}
486525
};
487526

488527
/******************************************************************************/
@@ -534,51 +573,29 @@ PermissionScopes.prototype.scopeKeyFromPageURL = function(url) {
534573
if ( !url || url === '*' ) {
535574
return '*';
536575
}
537-
var ut = uriTools.uri(url);
538-
var scheme = ut.scheme();
539-
var hostname = ut.hostname();
540-
if ( !hostname ) {
576+
var ut = uriTools;
577+
var scopeKey = ut.hostnameFromURI(url);
578+
if ( !scopeKey ) {
541579
return '*';
542580
}
543-
// if ( (/[^a-z0-9.-])/.test(hostname) ) {
581+
// if ( (/[^a-z0-9.-])/.test(scopeKey) ) {
544582
// throw new Error('Invalid URL: ' + url);
545583
// }
546-
// From narrowest scope to broadest scope
547-
// Try site scope
548-
var scopeKey = scheme + '://' + hostname;
584+
// From narrowest scope to broadest scope.
585+
// Try site scope.
549586
var scope = this.scopes[scopeKey];
550587
if ( scope && !scope.off ) {
551588
return scopeKey;
552589
}
553-
var secure = scheme === 'https';
554-
// If the connection is encrypted, it is then acceptable to apply
555-
// rules from unencrypted connection if any, because it is assumed the
556-
// rules for unencrypted connection are more restrictive.
557-
// The reverse is not true however.
558-
if ( secure ) {
559-
scopeKey = 'http://' + hostname;
560-
scope = this.scopes[scopeKey];
561-
if ( scope && !scope.off ) {
562-
return scopeKey;
563-
}
564-
}
565-
// Try domain scope
566-
var domain = ut.domainFromHostname(hostname);
567-
if ( !domain ) {
590+
// Try domain scope.
591+
scopeKey = ut.domainFromHostname(scopeKey);
592+
if ( !scopeKey ) {
568593
return '*';
569594
}
570-
scopeKey = scheme + '://*.' + domain;
571595
scope = this.scopes[scopeKey];
572596
if ( scope && !scope.off ) {
573597
return scopeKey;
574598
}
575-
if ( secure ) {
576-
scopeKey = 'http://*.' + domain;
577-
scope = this.scopes[scopeKey];
578-
if ( scope && !scope.off ) {
579-
return scopeKey;
580-
}
581-
}
582599
return '*';
583600
};
584601

js/popup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ function getClassSuffixFromScopeKey(scopeKey) {
11671167
if ( scopeKey === '*' ) {
11681168
return 'ScopeGlobal';
11691169
}
1170-
if ( /^https?:\/\/\*\./.test(scopeKey) ) {
1170+
if ( scopeKey.indexOf('*.') === 0 ) {
11711171
return 'ScopeDomain';
11721172
}
11731173
return 'ScopeSite';

js/rulemanager.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function renderScopeToRecipeString(scopeKey, scope) {
121121
}
122122

123123
function renderRecipeStringToScopeKey(recipe) {
124-
var parts = recipe.match(/^(\*|https?:\/\/(\*\.)?[-.:a-z0-9]+)$/);
124+
var parts = recipe.match(/^(\*|(https?:\/\/)?(\*\.)?[-.:a-z0-9]+)$/);
125125
if ( !parts ) {
126126
return false;
127127
}
@@ -172,6 +172,9 @@ function updateUglyRecipeWidget() {
172172
function beautifyRecipe(recipe) {
173173
try {
174174
recipe = decodeURIComponent(recipe.replace(/\n/g, '').trim()).replace(/\t/g, ' ');
175+
// rhill 2014-27-01: Remove scheme from scope keys.
176+
// https://github.com/gorhill/httpswitchboard/issues/165
177+
recipe = recipe.replace(/(^|\n)https?:\/\//g, '$1');
175178
$('#recipeUgly').removeClass('bad');
176179
}
177180
catch (e) {

0 commit comments

Comments
 (0)