Fix VcpkgComponent purl construction for names containing slashes#1752
Open
JamieMagee wants to merge 2 commits intomainfrom
Open
Fix VcpkgComponent purl construction for names containing slashes#1752JamieMagee wants to merge 2 commits intomainfrom
JamieMagee wants to merge 2 commits intomainfrom
Conversation
VcpkgComponent.PackageUrl built purl strings by interpolating
this.Name directly, e.g. $"pkg:vcpkg/{this.Name}@{this.Version}".
Vcpkg SPDX entries can have names like "google/brotli", which the
parser then misinterprets as namespace/name path segments. Names
with consecutive slashes cause an "empty segment" exception.
Use the PackageUrl component constructor instead, which treats
the name as a single component and percent-encodes it properly.
zhenghao104
reviewed
Mar 30, 2026
src/Microsoft.ComponentDetection.Contracts/TypedComponent/VcpkgComponent.cs
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes VcpkgComponent.PackageUrl construction so vcpkg component names containing / are correctly encoded/serialized into a valid Package URL (purl), avoiding parser failures caused by treating / as path separators.
Changes:
- Replace string-interpolated purl creation with
PackageUrl’s structured constructor. - Build
port_versionas an optional qualifiers dictionary whenPortVersion > 0.
src/Microsoft.ComponentDetection.Contracts/TypedComponent/VcpkgComponent.cs
Show resolved
Hide resolved
zhenghao104
approved these changes
Mar 30, 2026
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.
VcpkgComponent.PackageUrlbuilds purl strings by interpolatingthis.Namedirectly into a string like$"pkg:vcpkg/{this.Name}@{this.Version}". This breaks when vcpkg SPDX entries have names with slashes (e.g.google/brotli,capstone-engine/capstone), because the purl parser treats those slashes as path separators. If the name produces empty segments between slashes, parsing throwsMalformedPackageUrlException: The purl namespace has an empty segment between '/' separators.This switches to the
PackageUrlcomponent constructor, which accepts the name as a discrete parameter and handles encoding during serialization.