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

Commit d8e44e1

Browse files
committed
this fixes #248
1 parent 215a5e7 commit d8e44e1

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

js/httpsb.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,32 @@ HTTPSB.revertScopeRules = function(scopeKey) {
781781
return;
782782
}
783783
var pscope = this.permanentScopeFromScopeKey(scopeKey);
784-
// If no permanent scope found, use factory settings
785-
if ( !pscope ) {
786-
pscope = this.factoryScope;
784+
if ( pscope ) {
785+
// TODO: if global scope, intersect using ruleset
786+
tscope.assign(pscope);
787+
return;
788+
}
789+
790+
// https://github.com/gorhill/httpswitchboard/issues/248
791+
// If no permanent scope found, use generic rules in global scope
792+
tscope.removeAllRules();
793+
pscope = this.permanentScopeFromScopeKey('*');
794+
tscope.mtxFiltering = pscope.mtxFiltering;
795+
tscope.abpFiltering = pscope.abpFiltering;
796+
var listKeys = ['white', 'black'];
797+
var listKey, list;
798+
while ( listKey = listKeys.pop() ) {
799+
list = pscope[listKey];
800+
for ( var ruleKey in list.list ) {
801+
if ( list.list.hasOwnProperty(ruleKey) === false ) {
802+
continue;
803+
}
804+
// Mind only rules which apply on any domain
805+
if ( list.hostnameFromRuleKey(ruleKey) === '*' ) {
806+
tscope[listKey].addOne(ruleKey);
807+
}
808+
}
787809
}
788-
// TODO: if global scope, intersect using ruleset
789-
tscope.assign(pscope);
790810
};
791811

792812
/******************************************************************************/

js/lists.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ PermissionList.prototype.diffCount = function(other) {
172172
return count;
173173
};
174174

175+
/******************************************************************************/
176+
177+
PermissionList.prototype.typeFromRuleKey = function(ruleKey) {
178+
var pos = ruleKey.indexOf('|');
179+
return pos < 0 ? '' : ruleKey.slice(0, pos);
180+
};
181+
PermissionList.prototype.hostnameFromRuleKey = function(ruleKey) {
182+
var pos = ruleKey.indexOf('|');
183+
return pos < 0 ? '' : ruleKey.slice(pos + 1);
184+
};
185+
175186
/******************************************************************************/
176187
/******************************************************************************/
177188

@@ -218,6 +229,14 @@ PermissionScope.prototype.add = function(other) {
218229

219230
/******************************************************************************/
220231

232+
PermissionScope.prototype.removeAllRules = function() {
233+
this.white.removeAll();
234+
this.black.removeAll();
235+
this.gray.removeAll();
236+
};
237+
238+
/******************************************************************************/
239+
221240
PermissionScope.prototype.diffCount = function(other) {
222241
if ( !other ) {
223242
return this.white.count + this.black.count + this.gray.count + 2;

0 commit comments

Comments
 (0)