Skip to content

Commit f1665be

Browse files
author
Kapil Borle
committed
Fix settings hashtable input
Hashtable keys were compared in case-sensitive manner to lower case valid keys while adding values to the lists of severity, rule inclusion and rule exclusion. This commit also remove the relevant code duplication in ParseProfileHashtable and ParseProfileString while adding the values to the respective lists.
1 parent 4600e39 commit f1665be

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

Engine/ScriptAnalyzer.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,30 @@ internal bool ParseProfile(object profileObject, PathIntrinsics path, IOutputWri
216216
return true;
217217
}
218218

219+
private bool TryAddingProfileItem(
220+
string key,
221+
List<string> values,
222+
List<string> severityList,
223+
List<string> includeRuleList,
224+
List<string> excludeRuleList)
225+
{
226+
switch (key.ToLower())
227+
{
228+
case "severity":
229+
severityList.AddRange(values);
230+
break;
231+
case "includerules":
232+
includeRuleList.AddRange(values);
233+
break;
234+
case "excluderules":
235+
excludeRuleList.AddRange(values);
236+
break;
237+
default:
238+
return false;
239+
}
240+
return true;
241+
}
242+
219243
private bool ParseProfileHashtable(Hashtable profile, PathIntrinsics path, IOutputWriter writer,
220244
List<string> severityList, List<string> includeRuleList, List<string> excludeRuleList)
221245
{
@@ -238,7 +262,7 @@ private bool ParseProfileHashtable(Hashtable profile, PathIntrinsics path, IOutp
238262
hasError = true;
239263
continue;
240264
}
241-
265+
242266
// checks whether it falls into list of valid keys
243267
if (!validKeys.Contains(key))
244268
{
@@ -293,21 +317,8 @@ private bool ParseProfileHashtable(Hashtable profile, PathIntrinsics path, IOutp
293317
}
294318
}
295319

296-
// now add to the list
297-
switch (key)
298-
{
299-
case "severity":
300-
severityList.AddRange(values);
301-
break;
302-
case "includerules":
303-
includeRuleList.AddRange(values);
304-
break;
305-
case "excluderules":
306-
excludeRuleList.AddRange(values);
307-
break;
308-
default:
309-
break;
310-
}
320+
TryAddingProfileItem(key, values, severityList, includeRuleList, excludeRuleList);
321+
311322
}
312323

313324
return hasError;
@@ -426,23 +437,12 @@ private bool ParseProfileString(string profile, PathIntrinsics path, IOutputWrit
426437

427438
string key = (kvp.Item1 as StringConstantExpressionAst).Value.ToLower();
428439

429-
switch (key)
440+
if(!TryAddingProfileItem(key, rhsList, severityList, includeRuleList, excludeRuleList))
430441
{
431-
case "severity":
432-
severityList.AddRange(rhsList);
433-
break;
434-
case "includerules":
435-
includeRuleList.AddRange(rhsList);
436-
break;
437-
case "excluderules":
438-
excludeRuleList.AddRange(rhsList);
439-
break;
440-
default:
441-
writer.WriteError(new ErrorRecord(
442+
writer.WriteError(new ErrorRecord(
442443
new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.WrongKey, key, kvp.Item1.Extent.StartLineNumber, kvp.Item1.Extent.StartColumnNumber, profile)),
443444
Strings.WrongConfigurationKey, ErrorCategory.InvalidData, profile));
444-
hasError = true;
445-
break;
445+
hasError = true;
446446
}
447447
}
448448
}

0 commit comments

Comments
 (0)