@@ -421,77 +421,107 @@ private bool ParseProfileHashtable(Hashtable profile, PathIntrinsics path, IOutp
421421 validKeys . Add ( "severity" ) ;
422422 validKeys . Add ( "includerules" ) ;
423423 validKeys . Add ( "excluderules" ) ;
424+ validKeys . Add ( "rules" ) ;
424425
425426 foreach ( var obj in profile . Keys )
426427 {
427428 string key = obj as string ;
428-
429- // key should be a string
430429 if ( key == null )
431430 {
432- writer . WriteError ( new ErrorRecord ( new InvalidDataException ( string . Format ( CultureInfo . CurrentCulture , Strings . KeyNotString , key ) ) ,
433- Strings . ConfigurationKeyNotAString , ErrorCategory . InvalidData , profile ) ) ;
434- hasError = true ;
435- continue ;
436- }
437-
438- // checks whether it falls into list of valid keys
439- if ( ! validKeys . Contains ( key ) )
440- {
441- writer . WriteError ( new ErrorRecord (
442- new InvalidDataException ( string . Format ( CultureInfo . CurrentCulture , Strings . WrongKeyHashTable , key ) ) ,
443- Strings . WrongConfigurationKey , ErrorCategory . InvalidData , profile ) ) ;
431+ writer . WriteError (
432+ new ErrorRecord (
433+ new InvalidDataException ( string . Format ( CultureInfo . CurrentCulture , Strings . KeyNotString , key ) ) ,
434+ Strings . ConfigurationKeyNotAString ,
435+ ErrorCategory . InvalidData ,
436+ profile ) ) ;
444437 hasError = true ;
445438 continue ;
446439 }
447440
441+ key = key . ToLower ( ) ;
448442 object value = profile [ obj ] ;
449-
450- // value must be either string or collections of string or array
451- if ( value == null || ! ( value is string || value is IEnumerable < string > || value . GetType ( ) . IsArray ) )
443+ switch ( key )
452444 {
453- writer . WriteError ( new ErrorRecord (
454- new InvalidDataException ( string . Format ( CultureInfo . CurrentCulture , Strings . WrongValueHashTable , value , key ) ) ,
455- Strings . WrongConfigurationKey , ErrorCategory . InvalidData , profile ) ) ;
456- hasError = true ;
457- continue ;
458- }
459-
460- // if we get here then everything is good
461- List < string > values = new List < string > ( ) ;
462-
463- if ( value is string )
464- {
465- values . Add ( value as string ) ;
466- }
467- else if ( value is IEnumerable < string > )
468- {
469- values . Union ( value as IEnumerable < string > ) ;
470- }
471- else if ( value . GetType ( ) . IsArray )
472- {
473- // for array case, sometimes we won't be able to cast it directly to IEnumerable<string>
474- foreach ( var val in value as IEnumerable )
475- {
476- if ( val is string )
445+ case "severity" :
446+ case "includerules" :
447+ case "excluderules" :
448+ // value must be either string or collections of string or array
449+ if ( value == null
450+ || ! ( value is string
451+ || value is IEnumerable < string >
452+ || value . GetType ( ) . IsArray ) )
453+ {
454+ writer . WriteError (
455+ new ErrorRecord (
456+ new InvalidDataException ( string . Format ( CultureInfo . CurrentCulture , Strings . WrongValueHashTable , value , key ) ) ,
457+ Strings . WrongConfigurationKey ,
458+ ErrorCategory . InvalidData ,
459+ profile ) ) ;
460+ hasError = true ;
461+ break ;
462+ }
463+ List < string > values = new List < string > ( ) ;
464+ if ( value is string )
477465 {
478- values . Add ( val as string ) ;
466+ values . Add ( value as string ) ;
479467 }
480- else
468+ else if ( value is IEnumerable < string > )
481469 {
482- writer . WriteError ( new ErrorRecord (
483- new InvalidDataException ( string . Format ( CultureInfo . CurrentCulture , Strings . WrongValueHashTable , val , key ) ) ,
484- Strings . WrongConfigurationKey , ErrorCategory . InvalidData , profile ) ) ;
470+ values . Union ( value as IEnumerable < string > ) ;
471+ }
472+ else if ( value . GetType ( ) . IsArray )
473+ {
474+ // for array case, sometimes we won't be able to cast it directly to IEnumerable<string>
475+ foreach ( var val in value as IEnumerable )
476+ {
477+ if ( val is string )
478+ {
479+ values . Add ( val as string ) ;
480+ }
481+ else
482+ {
483+ writer . WriteError (
484+ new ErrorRecord (
485+ new InvalidDataException ( string . Format ( CultureInfo . CurrentCulture , Strings . WrongValueHashTable , val , key ) ) ,
486+ Strings . WrongConfigurationKey ,
487+ ErrorCategory . InvalidData ,
488+ profile ) ) ;
489+ hasError = true ;
490+ break ;
491+ }
492+ }
493+ }
494+ AddProfileItem ( key , values , severityList , includeRuleList , excludeRuleList ) ;
495+ settings [ key ] = values ;
496+ break ;
497+
498+ case "rules" :
499+ var ruleDict = value as Dictionary < string , object > ;
500+ if ( ruleDict == null )
501+ {
502+ writer . WriteError (
503+ new ErrorRecord (
504+ new InvalidDataException ( string . Format ( CultureInfo . CurrentCulture , Strings . WrongValueHashTable , value , key ) ) ,
505+ Strings . WrongConfigurationKey ,
506+ ErrorCategory . InvalidData ,
507+ profile ) ) ;
485508 hasError = true ;
486- continue ;
509+ break ;
487510 }
488- }
511+ settings [ key ] = ruleDict ;
512+ break ;
513+
514+ default :
515+ writer . WriteError (
516+ new ErrorRecord (
517+ new InvalidDataException ( string . Format ( CultureInfo . CurrentCulture , Strings . WrongKeyHashTable , key ) ) ,
518+ Strings . WrongConfigurationKey ,
519+ ErrorCategory . InvalidData ,
520+ profile ) ) ;
521+ hasError = true ;
522+ break ;
489523 }
490-
491- AddProfileItem ( key , values , severityList , includeRuleList , excludeRuleList ) ;
492-
493524 }
494-
495525 return hasError ;
496526 }
497527
0 commit comments