@@ -299,6 +299,14 @@ function applyCSSSelector(details, selector) {
299299 return modified ;
300300}
301301
302+ function logError ( writer , msg ) {
303+ logger . writeOne ( {
304+ realm : 'message' ,
305+ type : 'error' ,
306+ text : msg . replace ( '{who}' , writer . properties . get ( 'name' ) || '?' )
307+ } ) ;
308+ }
309+
302310htmlFilteringEngine . reset = function ( ) {
303311 filterDB . clear ( ) ;
304312 pselectors . clear ( ) ;
@@ -316,13 +324,7 @@ htmlFilteringEngine.compile = function(parser, writer) {
316324 const isException = parser . isException ( ) ;
317325 const { raw, compiled } = parser . result ;
318326 if ( compiled === undefined ) {
319- const who = writer . properties . get ( 'name' ) || '?' ;
320- logger . writeOne ( {
321- realm : 'message' ,
322- type : 'error' ,
323- text : `Invalid HTML filter in ${ who } : ##${ raw } `
324- } ) ;
325- return ;
327+ return logError ( writer , `Invalid HTML filter in {who}: ##${ raw } ` ) ;
326328 }
327329
328330 writer . select ( 'HTML_FILTERS' ) ;
@@ -335,20 +337,28 @@ htmlFilteringEngine.compile = function(parser, writer) {
335337 return ;
336338 }
337339
338- // TODO: Mind negated hostnames, they are currently discarded.
339-
340+ const compiledFilters = [ ] ;
341+ let hasOnlyNegated = true ;
340342 for ( const { hn, not, bad } of parser . getExtFilterDomainIterator ( ) ) {
341343 if ( bad ) { continue ; }
342- let kind = 0 ;
343- if ( isException ) {
344- if ( not ) { continue ; }
345- kind |= 0b01 ;
344+ let kind = isException ? 0b01 : 0b00 ;
345+ if ( not ) {
346+ kind ^= 0b01 ;
347+ } else {
348+ hasOnlyNegated = false ;
346349 }
347350 if ( compiled . charCodeAt ( 0 ) === 0x7B /* '{' */ ) {
348351 kind |= 0b10 ;
349352 }
350- writer . push ( [ 64 , hn , kind , compiled ] ) ;
353+ compiledFilters . push ( [ 64 , hn , kind , compiled ] ) ;
354+ }
355+
356+ // Not allowed since it's equivalent to forbidden generic HTML filters
357+ if ( isException === false && hasOnlyNegated ) {
358+ return logError ( writer , `Invalid HTML filter in {who}: ##${ raw } ` ) ;
351359 }
360+
361+ writer . pushMany ( compiledFilters ) ;
352362} ;
353363
354364htmlFilteringEngine . fromCompiledContent = function ( reader ) {
0 commit comments