@@ -226,14 +226,14 @@ PermissionScope.prototype.evaluate = function(type, hostname) {
226226 var blacklist = this . black . list ;
227227 var whitelist = this . white . list ;
228228 var graylist = this . gray . list ;
229- var typeKey , cellKey ;
229+ var cellKey ;
230230 var parents , parent , i ;
231231
232232 // Pick proper entry point
233233
234234 if ( type !== '*' && hostname !== '*' ) {
235235 // https://github.com/gorhill/httpswitchboard/issues/29
236- typeKey = type + '|*' ;
236+ var typeKey = type + '|*' ;
237237
238238 // direct: specific type, specific hostname
239239 cellKey = type + '|' + hostname ;
@@ -244,11 +244,41 @@ PermissionScope.prototype.evaluate = function(type, hostname) {
244244 return 'rdt' ;
245245 }
246246
247+ var strictBlocking = httpsb . userSettings . strictBlocking ;
248+ parents = uriTools . parentHostnamesFromHostname ( hostname ) ;
249+
250+ cellKey = '*|' + hostname ;
251+ if ( whitelist [ cellKey ] ) {
252+ // If strict blocking, the type column must not be
253+ // blacklisted
254+ if ( strictBlocking ) {
255+ i = 0 ;
256+ while ( parent = parents [ i ++ ] ) {
257+ cellKey = type + '|' + parent ;
258+ if ( whitelist [ cellKey ] ) {
259+ return 'gpt' ;
260+ }
261+ if ( blacklist [ cellKey ] ) {
262+ return 'rpt' ;
263+ }
264+ }
265+ if ( whitelist [ typeKey ] ) {
266+ return 'gpt' ;
267+ }
268+ if ( blacklist [ typeKey ] ) {
269+ return 'rpt' ;
270+ }
271+ }
272+ return 'gpt' ;
273+ }
274+ if ( blacklist [ cellKey ] || ( ! graylist [ cellKey ] && blacklistReadonly [ hostname ] ) ) {
275+ return 'rpt' ;
276+ }
277+
247278 // rhill 2013-12-18:
248279 // If the type is blocked and strict blocking is on,
249280 // than the only way for the cell to be whitelisted is
250281 // by having an ancestor explicitly whitelisted
251- parents = uriTools . parentHostnamesFromHostname ( hostname ) ;
252282 i = 0 ;
253283 while ( parent = parents [ i ++ ] ) {
254284 cellKey = type + '|' + parent ;
@@ -258,35 +288,34 @@ PermissionScope.prototype.evaluate = function(type, hostname) {
258288 if ( blacklist [ cellKey ] ) {
259289 return 'rpt' ;
260290 }
261- }
262-
263- // if we reach this point and the type is blacklisted and strict
264- // blocking is on, the cell can't be green.
265- if ( blacklist [ typeKey ] && httpsb . userSettings . strictBlocking ) {
266- return 'rpt' ;
267- }
268-
269- // if we reach this point, strict blocking is off or the type
270- // is not blacklisted, which means that we can meaningfully evaluate
271- // hostname or ancestor hostnames.
272- cellKey = '*|' + hostname ;
273- if ( whitelist [ cellKey ] ) {
274- return 'gpt' ;
275- }
276- if ( blacklist [ cellKey ] || ( ! graylist [ cellKey ] && blacklistReadonly [ hostname ] ) ) {
277- return 'rpt' ;
278- }
279- i = 0 ;
280- while ( parent = parents [ i ++ ] ) {
281291 cellKey = '*|' + parent ;
282- // specific type, specific parent
283292 if ( whitelist [ cellKey ] ) {
293+ // If strict blocking, the type column must not be
294+ // blacklisted
295+ if ( strictBlocking ) {
296+ while ( parent = parents [ i ++ ] ) {
297+ cellKey = type + '|' + parent ;
298+ if ( whitelist [ cellKey ] ) {
299+ return 'gpt' ;
300+ }
301+ if ( blacklist [ cellKey ] ) {
302+ return 'rpt' ;
303+ }
304+ }
305+ if ( whitelist [ typeKey ] ) {
306+ return 'gpt' ;
307+ }
308+ if ( blacklist [ typeKey ] ) {
309+ return 'rpt' ;
310+ }
311+ }
284312 return 'gpt' ;
285313 }
286314 if ( blacklist [ cellKey ] || ( ! graylist [ cellKey ] && blacklistReadonly [ parent ] ) ) {
287315 return 'rpt' ;
288316 }
289317 }
318+
290319 // indirect: specific type, any hostname
291320 if ( whitelist [ typeKey ] ) {
292321 return 'gpt' ;
0 commit comments