Skip to content

Report unclosed quotes in response files#8448

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-unclosed-quotes-in-response-files
Open

Report unclosed quotes in response files#8448
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-unclosed-quotes-in-response-files

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 21, 2026

Malformed quoted tokens in response files were silently accepted, causing unterminated arguments to be dropped while TryReadResponseFile still reported success. This can turn a response-file typo into misleading or partial command-line parsing.

  • Response file parsing

    • Detects unbalanced quotes while splitting response-file lines.
    • Converts malformed response-file syntax into a failed TryReadResponseFile result.
    • Includes the response file path and line number in the reported error.
  • Tokenization behavior

    • SplitCommandLine now rejects unterminated quoted input instead of returning an empty or partial result.
--filter "FullyQualifiedName~My.Namespace

Now reports a response-file parse error instead of silently dropping the filter argument.

  • Coverage
    • Adds focused coverage for malformed quoted input in response files.
    • Updates the direct tokenizer test to expect a parse failure for unclosed quotes.

Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 08:05
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 08:14
Copilot AI changed the title [WIP] Fix unclosed quotes in response files handling Report unclosed quotes in response files May 21, 2026
Copilot AI requested a review from Evangelink May 21, 2026 08:15
@Evangelink Evangelink marked this pull request as ready for review May 21, 2026 09:25
Copilot AI review requested due to automatic review settings May 21, 2026 09:25
Copy link
Copy Markdown
Contributor

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.

Pull request overview

This pull request improves Microsoft.Testing.Platform command-line response file handling by treating malformed quoted tokens as parsing errors (rather than silently accepting and dropping unterminated arguments), and updates unit tests to cover the new behavior.

Changes:

  • Detect and fail response-file parsing when a line contains an unclosed quote, including reporting the response-file line number.
  • Update SplitCommandLine to reject unterminated quoted input by throwing FormatException.
  • Add/adjust unit tests to validate the new failure behavior for malformed quoted input.
Show a summary per file
File Description
test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs Adds coverage for unclosed quotes in response files and updates tokenizer test expectations to require failure.
src/Platform/Microsoft.Testing.Platform/CommandLine/ResponseFileHelper.cs Adds line-aware tokenization for response-file lines and throws FormatException on unclosed quotes; TryReadResponseFile converts format errors into a failed result.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread src/Platform/Microsoft.Testing.Platform/CommandLine/ResponseFileHelper.cs Outdated
- Catch UnauthorizedAccessException in TryReadResponseFile and report via the standard CommandLineParserFailedToReadResponseFile error path.
- Move unclosed-quote FormatException messages into PlatformResources for localization and drop trailing periods to avoid doubled punctuation when wrapped by CommandLineParserFailedToReadResponseFile.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

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

This was a copy from System.CommandLine. I would be skeptical to making changes here without validating System.CommandLine behavior first and even then, I would fix it in S.CL first before making a change here.

Comment on lines +26 to +33
catch (UnauthorizedAccessException e)
{
errors.Add(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineParserFailedToReadResponseFile, rspFilePath, e.Message));
}
catch (FormatException e)
{
errors.Add(string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineParserFailedToReadResponseFile, rspFilePath, e.Message));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds unrelated to what the PR wants to do.

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.

[MTP Core Analysis] Unclosed quotes in response files are silently ignored

4 participants