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

OnlyCheckWhitespaceInsideParenthesis Fixes #5863 #5868

Merged
merged 8 commits into from
Nov 11, 2020

Conversation

Forgind
Copy link
Member

@Forgind Forgind commented Nov 6, 2020

This weakens the check somewhat, since it only checks just inside parentheses, but that allows people to put spaces in, say, property conditions after a comma.

Fixes #5863

This weakens the check somewhat, since it only checks just inside parentheses, but that allows people to put spaces in, say, property conditions after a comma.
Copy link
Member

@benvillalobos benvillalobos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mentioned you wanted this out quick, but definitely needs a few tests before merging.

@@ -333,17 +331,20 @@ private static bool ScanForPropertyExpressionEnd(string expression, int index, o
if (character == '(')
{
nestLevel++;
whitespaceCheck = true;
if (index + 1 < expression.Length && char.IsWhiteSpace(pchar[index + 1]) && ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave16_10))
Copy link
Member

@benvillalobos benvillalobos Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only care about a space after an open parens and before a close parens? What about before / after each one? That's the case here: #5863
<ItemGroup Condition="$(Foo.StartsWith ('A'))">

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, so we should ignore cases like that because we don't want them to fail.

@@ -325,33 +325,35 @@ private static bool ScanForPropertyExpressionEnd(string expression, int index, o
{
fixed (char* pchar = expression)
{
if (expression.Length > 1 && pchar[0] == '(' && char.IsWhiteSpace(pchar[1]) && ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave16_10))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the first character in the expression guaranteed to be a '('?

Should this maybe move under the `if (character == '(')?

Something like:

                        if (character == '(')
                        {
                             if (nestLevel == 0 && index + 1 > expression.Length && pchar[index + 1] == '(' && char.IsWhiteSpace(pchar[1]) && ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave16_10))
                              {
                                    indexResult = 1;
                                     return false;
                              }
                            nestLevel++;
                        }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi, @mfkl

Comment on lines 122 to 123
[InlineData("$(x x)")]
[InlineData("$(y d f ( hi ) sx)")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are examples of things we wish we could catch but we can't with current limitations. Can you instead use examples we want to work like

Suggested change
[InlineData("$(x x)")]
[InlineData("$(y d f ( hi ) sx)")]
[InlineData("$(x.StartsWith( 'y' ))")]
[InlineData("$(x.StartsWith ('y'))")]

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking at this, I think even starts/ends with space is too aggressive. $( x.StartsWith ( y ) ) is a bit ugly but works just fine today. Maybe it has to be "has a space and is otherwise only identifier characters"? That would correctly reject $(x x) from your examples here.

src/Build.UnitTests/Scanner_Tests.cs Outdated Show resolved Hide resolved
src/Build/Evaluation/Conditionals/Scanner.cs Show resolved Hide resolved
src/Build.UnitTests/Scanner_Tests.cs Show resolved Hide resolved
src/Build/Evaluation/Conditionals/Scanner.cs Outdated Show resolved Hide resolved
[InlineData("$(x.StartsWith( 'y' ))")]
[InlineData("$(x.StartsWith ('y'))")]
[InlineData("$( x.StartsWith( $(SpacelessProperty) ) )")]
[InlineData("$( x.StartsWith( $(_SpacelessProperty) ) )")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One case I ran into was something like:

[InlineData("$(x.StartsWith('Foo', StringComparison.InvariantCultureIgnoreCase))")]

It might already work with the changes here, but might be good to add this case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do please add this multiple-argument case before merging.

[InlineData("$(x.StartsWith( 'y' ))")]
[InlineData("$(x.StartsWith ('y'))")]
[InlineData("$( x.StartsWith( $(SpacelessProperty) ) )")]
[InlineData("$( x.StartsWith( $(_SpacelessProperty) ) )")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do please add this multiple-argument case before merging.

@Forgind Forgind merged commit 56ab634 into dotnet:master Nov 11, 2020
@Forgind Forgind deleted the whitespace-fix branch November 11, 2020 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.NET 6: error MSB4259: Unexpected space at position N Did you forget to remove a space?
4 participants