Skip to content

Commit

Permalink
added more checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Amitla Vannikumar committed Oct 17, 2023
1 parent a54cb7c commit 826a358
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Microsoft.ComponentDetection.Contracts.TypedComponent;

using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using PackageUrl;

Expand Down Expand Up @@ -89,14 +91,22 @@ private void SetGitRepoProperties()
* "git+https://github.com/Microsoft/vcpkg#ports/nlohmann-json"
*/
var locationArr = this.DownloadLocation.Split('/');

if (locationArr.Length > 4)
{
return;
}

if (!string.IsNullOrEmpty(locationArr[2]))
{
this.GitRepositoryOwner = locationArr[2];
}

var allowedGitRepoNameChars = new List<char> { '_', '-', '.', '\'' };

if (!string.IsNullOrEmpty(locationArr[3]))
{
this.GitRepositoryName = locationArr[3].TakeWhile(ch => char.IsLetterOrDigit(ch)).ToString();
this.GitRepositoryName = locationArr[3].TakeWhile(ch => char.IsLetterOrDigit(ch) || allowedGitRepoNameChars.Contains(ch)).ToString();
}
}
}

0 comments on commit 826a358

Please sign in to comment.