Skip to content

Conversation

@nohwnd
Copy link
Member

@nohwnd nohwnd commented Oct 31, 2025

Description

The code was last touched here #1196 fixing some indeterminate issues with the parsing. Seeing the examples in tests it handles quotes differently and backslashes.

However the code runs out of bounds (not a problem but throws index out of range unnecessarilly).

And fails to recognize \" that is in quoted string. It detects the \", but the index is not advanced past that ", so in the next steps is incorrectly stops being a quoted string and spaces will split the command into more tokens.

This is problematic for providing /Tests: which provides the whole test name including spaces etc, in format like this:

/Tests:"UpdateTest.CheckUpdate("C:\\Data\\Config.xml","C:\\Data\\Config","C:\\Data\\User"),UpdateTest.MyTest(\"Lorem Ipsum\")"
mytests.dll

The previous logic would split the parameters to be:

/Tests:UpdateTest.CheckUpdate("C:\\Data\\Config.xml","C:\\Data\\Config","C:\\Data\\User"),UpdateTest.MyTest(\"Lorem
Ipsum\")
mytests.dll

And would fail with Ipsum\") test source not found.

New logic correctly splits it to:

/Tests:UpdateTest.CheckUpdate("C:\\Data\\Config.xml","C:\\Data\\Config","C:\\Data\\User"),UpdateTest.MyTest(\"Lorem Ipsum\")
mytests.dll

I have a much larger file from the issue, but it contains customer data, and the spaces are the only edge case that triggers this problem.

Related issue

https://developercommunity.visualstudio.com/t/vstest-task-fails-with-Unhandled-Except/10527048

@nohwnd nohwnd requested a review from Copilot October 31, 2025 16:35
@nohwnd
Copy link
Member Author

nohwnd commented Oct 31, 2025

@copilot anything that the previous code handled and that I don't test for in the new code?

// If the char after '\' is a '"', output '"' and skip over to the next char.
if (index <= args.Length && args[index] == '"')
{
currentArg.Append('"');
Copy link
Member Author

@nohwnd nohwnd Oct 31, 2025

Choose a reason for hiding this comment

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

Main bug was here imho. We handled the quote, but we don't advance to the next character because the logic is trying to be too clever with the \ being or not being doubled.

The " is then processed in the next loop, and stops the string from being quoted, even though the quote was escaped.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

1 participant