From 8331bbfca853961858c8af4bb1954c084e6b2991 Mon Sep 17 00:00:00 2001 From: Amitla Vannikumar Date: Sun, 15 Oct 2023 03:17:12 -0700 Subject: [PATCH] changed download location parsing to sanitize better --- .../TypedComponent/VcpkgComponent.cs | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Contracts/TypedComponent/VcpkgComponent.cs b/src/Microsoft.ComponentDetection.Contracts/TypedComponent/VcpkgComponent.cs index 399683725..09121ab2f 100644 --- a/src/Microsoft.ComponentDetection.Contracts/TypedComponent/VcpkgComponent.cs +++ b/src/Microsoft.ComponentDetection.Contracts/TypedComponent/VcpkgComponent.cs @@ -1,5 +1,6 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent; +using System.Linq; using PackageUrl; public class VcpkgComponent : TypedComponent @@ -20,9 +21,11 @@ public VcpkgComponent(string spdxid, string name, string version, string triplet this.Triplet = triplet; this.Description = description; this.DownloadLocation = downloadLocation; - var locationArr = downloadLocation.Split('/'); - this.GitRepositoryOwner = locationArr[3]; - this.GitRepositoryName = locationArr[4].Split('@')[0]; + + if (downloadLocation.ToLower().Contains("https://github.com/")) + { + this.SetGitRepoProperties(); + } } public string SPDXID { get; set; } @@ -31,10 +34,6 @@ public VcpkgComponent(string spdxid, string name, string version, string triplet public string DownloadLocation { get; set; } - public string GitRepositoryOwner { get; set; } - - public string GitRepositoryName { get; set; } - public string Triplet { get; set; } public string Version { get; set; } @@ -43,8 +42,23 @@ public VcpkgComponent(string spdxid, string name, string version, string triplet public int PortVersion { get; set; } + public string GitRepositoryOwner { get; set; } + + public string GitRepositoryName { get; set; } + public override ComponentType Type => ComponentType.Vcpkg; + private void SetGitRepoProperties() + { + /* example download locations + * "git+https://github.com/leethomason/tinyxml2@9.0.0" + * "git+https://github.com/Microsoft/vcpkg#ports/nlohmann-json" + */ + var locationArr = this.DownloadLocation.Split('/'); + this.GitRepositoryOwner = locationArr[2]; + this.GitRepositoryName = locationArr[3].TakeWhile(ch => char.IsLetterOrDigit(ch)).ToString(); + } + public override string Id { get