@@ -154,11 +154,20 @@ RuleSets.prototype = {
154154 this . targets [ host ] . push ( rule_set ) ;
155155 }
156156 } ,
157+
158+ setInsert : function ( intoList , fromList ) {
159+ // Insert any elements from fromList into intoList, if they are not
160+ // already there. fromList may be null.
161+ if ( ! fromList ) return ;
162+ for ( var i = 0 ; i < fromList . length ; i ++ )
163+ if ( intoList . indexOf ( fromList [ i ] ) == - 1 )
164+ intoList . push ( fromList [ i ] ) ;
165+ } ,
157166
158167 potentiallyApplicableRulesets : function ( host ) {
159168 // Return a list of rulesets that apply to this host
160169 var i , tmp , t ;
161- var results = this . global_rulesets ;
170+ var results = this . global_rulesets . slice ( 0 ) ; // copy global_rulesets
162171 if ( this . targets [ host ] )
163172 results = results . concat ( this . targets [ host ] ) ;
164173 // replace each portion of the domain with a * in turn
@@ -168,15 +177,13 @@ RuleSets.prototype = {
168177 segmented [ i ] = "*" ;
169178 t = segmented . join ( "." ) ;
170179 segmented [ i ] = tmp ;
171- if ( this . targets [ t ] )
172- results = results . concat ( this . targets [ t ] ) ;
180+ this . setInsert ( results , this . targets [ t ] ) ;
173181 }
174182 // now eat away from the left, with *, so that for x.y.z.google.com we
175183 // check *.z.google.com and *.google.com (we did *.y.z.google.com above)
176- for ( i = 1 ; i <= segmented . length - 2 ; ++ i ) {
184+ for ( i = 1 ; i < segmented . length - 2 ; ++ i ) {
177185 t = "*." + segmented . slice ( i , segmented . length ) . join ( "." ) ;
178- if ( this . targets [ t ] )
179- results = results . concat ( this . targets [ t ] ) ;
186+ this . setInsert ( results , this . targets [ t ] ) ;
180187 }
181188 log ( DBUG , "Applicable rules for " + host + ":" ) ;
182189 if ( results . length == 0 )
0 commit comments