This repository was archived by the owner on Nov 15, 2017. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +44
-5
lines changed
Expand file tree Collapse file tree 2 files changed +44
-5
lines changed Original file line number Diff line number Diff 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/******************************************************************************/
Original file line number Diff line number Diff 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+
221240PermissionScope . prototype . diffCount = function ( other ) {
222241 if ( ! other ) {
223242 return this . white . count + this . black . count + this . gray . count + 2 ;
You can’t perform that action at this time.
0 commit comments