Skip to content

Fix settings hashtable input #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 37 additions & 30 deletions Engine/ScriptAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Collections;
using System.Diagnostics;

namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
{
Expand Down Expand Up @@ -216,6 +217,36 @@ internal bool ParseProfile(object profileObject, PathIntrinsics path, IOutputWri
return true;
}

private bool AddProfileItem(
string key,
List<string> values,
List<string> severityList,
List<string> includeRuleList,
List<string> excludeRuleList)
{
Debug.Assert(key != null);
Debug.Assert(values != null);
Debug.Assert(severityList != null);
Debug.Assert(includeRuleList != null);
Debug.Assert(excludeRuleList != null);

switch (key.ToLower())
{
case "severity":
severityList.AddRange(values);
break;
case "includerules":
includeRuleList.AddRange(values);
break;
case "excluderules":
excludeRuleList.AddRange(values);
break;
default:
return false;
}
return true;
}

private bool ParseProfileHashtable(Hashtable profile, PathIntrinsics path, IOutputWriter writer,
List<string> severityList, List<string> includeRuleList, List<string> excludeRuleList)
{
Expand All @@ -238,7 +269,7 @@ private bool ParseProfileHashtable(Hashtable profile, PathIntrinsics path, IOutp
hasError = true;
continue;
}

// checks whether it falls into list of valid keys
if (!validKeys.Contains(key))
{
Expand Down Expand Up @@ -293,21 +324,8 @@ private bool ParseProfileHashtable(Hashtable profile, PathIntrinsics path, IOutp
}
}

// now add to the list
switch (key)
{
case "severity":
severityList.AddRange(values);
break;
case "includerules":
includeRuleList.AddRange(values);
break;
case "excluderules":
excludeRuleList.AddRange(values);
break;
default:
break;
}
AddProfileItem(key, values, severityList, includeRuleList, excludeRuleList);

}

return hasError;
Expand Down Expand Up @@ -426,23 +444,12 @@ private bool ParseProfileString(string profile, PathIntrinsics path, IOutputWrit

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

switch (key)
if(!AddProfileItem(key, rhsList, severityList, includeRuleList, excludeRuleList))
{
case "severity":
severityList.AddRange(rhsList);
break;
case "includerules":
includeRuleList.AddRange(rhsList);
break;
case "excluderules":
excludeRuleList.AddRange(rhsList);
break;
default:
writer.WriteError(new ErrorRecord(
writer.WriteError(new ErrorRecord(
new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.WrongKey, key, kvp.Item1.Extent.StartLineNumber, kvp.Item1.Extent.StartColumnNumber, profile)),
Strings.WrongConfigurationKey, ErrorCategory.InvalidData, profile));
hasError = true;
break;
hasError = true;
}
}
}
Expand Down