X Tutup
The Wayback Machine - https://web.archive.org/web/20200918094704/https://github.com/PowerShell/PSScriptAnalyzer/pull/1161
Skip to content
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

Fix settings file array parsing when no commas are present #1161

Merged

Conversation

@rjmholt
Copy link
Member

rjmholt commented Mar 1, 2019

PR Summary

Fixes #1160.

The settings parsing logic didn't automatically capture arrays where elements are separated by newline.

I've fix that in the parser and added some tests to make sure it stays fixed.

PR Checklist

@rjmholt rjmholt requested review from bergmeister and JamesWTruher Mar 1, 2019
Engine/Settings.cs Outdated Show resolved Hide resolved
Copy link
Collaborator

bergmeister left a comment

Looks good to me with only a minor/optional style improvement suggestion.

@@ -522,6 +522,9 @@ private static object GetSafeValueFromExpressionAst(ExpressionAst exprAst)
case "false":
return false;

case "null":

This comment has been minimized.

@rjmholt

rjmholt Mar 1, 2019 Author Member

Noticed this was missing and quickly added it. Makes sense from a layering perspective -- null should be parse-able but might not be allowed as a configurable value.

This comment has been minimized.

@bergmeister

bergmeister Mar 1, 2019 Collaborator

What about just simplifying the whole code to bool.tryparse ?

This comment has been minimized.

@rjmholt

rjmholt Mar 2, 2019 Author Member

If one of the possibilities is null, then it would probably look like:

string varName = varExprAst.VariablePath.UserPath.ToLower();
if (bool.TryParse(varName, out bool val))
{
    return val;
}

if (varName == "null")
{
    return null;
}

throw CreateInvalidDataExceptionFromAst(varExprAst);

I'm not sure that's simpler though -- the switch/case has a nice flow to me, and ideally the C# compiler knows better than I do about how to make it work quickly. (Although it looks like that's not the case, since I would implement a trie for optimum speed).

Tests/Engine/Settings.tests.ps1 Show resolved Hide resolved
rjmholt added 2 commits Mar 1, 2019
@JamesWTruher JamesWTruher merged commit 2104f05 into PowerShell:development Mar 7, 2019
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
license/cla All CLA requirements met.
Details
bergmeister added a commit to bergmeister/PSScriptAnalyzer that referenced this pull request Mar 22, 2019
…l#1161)

* Fix settings file array parsing when no commas are present

* Add extra test

* Improve comment

* Add test file

* Change test to accept null

* Fix new-item call in PS 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.
X Tutup