Quote manifest path when invoking cargo metadata - #1870
Open
RKS (rksharma-owg) wants to merge 1 commit into
Open
RKS (rksharma-owg) wants to merge 1 commit into
RKS (rksharma-owg) wants to merge 1 commit into
Conversation
When scanning Rust projects located in paths containing spaces, the unquoted manifest path passed after --manifest-path is split by the underlying command invocation mechanism, causing cargo metadata to fail with 'unexpected argument found'. This change wraps the manifest path in quotes if it contains spaces and is not already quoted, in both RustCliParser and RustMetadataContextBuilder.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes directly address the reported argument-splitting failure and include targeted tests covering the new quoting behavior.
Pull request overview
This PR fixes Rust scanning failures when cargo metadata is invoked with a --manifest-path that contains spaces, which previously caused the path to be split into multiple arguments due to parameter joining in CommandLineInvocationService.
Changes:
- Quote
Cargo.tomlmanifest paths (when they contain spaces) before passing them tocliService.ExecuteCommandAsyncin the Rust CLI parser and metadata context builder. - Add unit tests verifying the quoted manifest-path argument is used when the path contains spaces.
File summaries
| File | Description |
|---|---|
src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustCliParser.cs |
Quotes the --manifest-path argument when componentStream.Location contains spaces. |
src/Microsoft.ComponentDetection.Detectors/rust/RustMetadataContextBuilder.cs |
Quotes the --manifest-path argument when the provided manifest path contains spaces. |
test/Microsoft.ComponentDetection.Detectors.Tests/RustCliParserTests.cs |
Adds a test asserting cargo metadata is invoked with a quoted manifest path when the path contains spaces. |
test/Microsoft.ComponentDetection.Detectors.Tests/RustMetadataContextBuilderTests.cs |
Adds a test asserting ownership-map building invokes cargo metadata with a quoted manifest path when the path contains spaces. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an issue where invoking
cargo metadatafails when the path toCargo.tomlcontains spaces.Fixes #1467
Problem
When scanning a Rust project whose path contains spaces (such as paths with spaces in folder names like
AppControl Manageror workspace names),RustCliParserandRustMetadataContextBuilderpass the raw file path directly following the--manifest-pathparameter incliService.ExecuteCommandAsync.Because the command line invocation service joins parameters with spaces (
string.Join(" ", parameters)), the unquoted path is split by the process launcher/Cargo CLI argument parser into multiple arguments. As a result, Cargo aborts with an error such as:error: unexpected argument '<PathSnippet>' foundcausing the CLI scan to fail and fallback behavior to be triggered or fail.
Solution
RustCliParser.cs, wrapcomponentStream.Locationin quotes if it contains spaces and is not already quoted.RustMetadataContextBuilder.cs, wrapmanifestPathin quotes if it contains spaces and is not already quoted.Tests
ParseAsync_QuotesManifestPathWhenPathContainsSpacesinRustCliParserTests:cargo metadatais invoked with the manifest path wrapped in quotes when the path contains spaces.BuildPackageOwnershipMapAsync_QuotesManifestPathWhenPathContainsSpacesinRustMetadataContextBuilderTests:RustMetadataContextBuildercorrectly quotes the manifest path when callingcargo metadatafor ownership map building.RustCliParserTests(37 tests) andRustMetadataContextBuilderTests(14 tests) continue to pass.