Skip to content

Commit

Permalink
require string
Browse files Browse the repository at this point in the history
  • Loading branch information
Amitla Vannikumar committed Oct 10, 2024
1 parent 6e24996 commit eaadac1
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace Microsoft.ComponentDetection.Detectors.Go;

public class GoComponentDetector : FileComponentDetector
{
private const string StartString = "require ";

private static readonly Regex GoSumRegex = new(
@"(?<name>.*)\s+(?<version>.*?)(/go\.mod)?\s+(?<hash>.*)",
RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
Expand Down Expand Up @@ -287,7 +289,6 @@ private async Task ParseGoModFileAsync(
GoGraphTelemetryRecord goGraphTelemetryRecord)
{
using var reader = new StreamReader(file.Stream);
var startString = "require ";

// There can be multiple require( ) sections in go 1.17+. loop over all of them.
while (!reader.EndOfStream)
Expand All @@ -303,9 +304,9 @@ private async Task ParseGoModFileAsync(

// In go >= 1.17, direct dependencies are listed as "require x/y v1.2.3", and transitive dependencies
// are listed in the require () section
if (line.StartsWith(startString))
if (line.StartsWith(StartString))
{
this.TryRegisterDependencyFromModLine(line[startString.Length..], singleFileComponentRecorder);
this.TryRegisterDependencyFromModLine(line[StartString.Length..], singleFileComponentRecorder);
}

line = await reader.ReadLineAsync();
Expand Down

0 comments on commit eaadac1

Please sign in to comment.