dotnet / dotnet/msbuild

[Bug]: ExpressionShredder.GetReferencedItemNamesAndMetadata expression parser does not handle nested quotes

Open
#9,940 0 comments 0 reactions 0 assignees View on GitHub
Area: Language backlog bug Priority:3 triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Issue Description

Task batching on item metadata does not handle complicated expressions like `@(a->'$(...)')` properly, leading to misdetection of metadata to batch on and/or build errors. The following minimal reproducible example illustrates the problem. I put additional explanations and analysis in MRE comments.

### Steps to Reproduce

Uncomment the fragment creating `d` items to see the error.
```xml


m0


m1


m0
x1


m1




@(b->'%(m)')






@(c->'$([System.String]::new('%(m)').Replace('x',%(n)))')








```

### Expected Behavior

`ExpressionShredder.GetReferencedItemNamesAndMetadata` correctly skips the whole quoted expression and does not pick up `m` as a metadata to batch on.

### Actual Behavior

`ExpressionShredder.GetReferencedItemNamesAndMetadata` mangles the expression and picks up `m` as a metadata to batch on. In the above MRE this produces a build error because `a` items do not have the `m` metadata.

### Analysis

The reason for this is that `ExpressionShredder.GetReferencedItemNamesAndMetadata` stops parsing a quoted expression at the first closing quote, which happens to be in the middle of an expression. It does not find the closing brace there, restarts skipping the leading `@`, and keeps skipping leading characters of the expression until it finds and parses the `%(m)` in the middle of the expression.

### Versions & Configurations

Verified with `msbuild` 17.8.5 and with `msbuild` built from HEAD (2e6f2ff7ea311214255b6b2ca5cc0554fba1b345).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.