Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing null reference when using VersionControlInformation #2222

Merged
merged 4 commits into from
Jan 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Sarif/Visitors/InsertOptionalDataVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -40,6 +41,7 @@ public InsertOptionalDataVisitor(
_dataToInsert = dataToInsert;
_originalUriBaseIds = originalUriBaseIds;
_ruleIndex = -1;
_gitHelper = new GitHelper();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHelper [](start = 29, length = 9)

Let's change the insert data option name that was broken to VersionControlDetails (from VersionControlInformation)

}

public override Run VisitRun(Run node)
Expand All @@ -50,7 +52,7 @@ public override Run VisitRun(Run node)

if (_originalUriBaseIds != null)
{
_run.OriginalUriBaseIds = _run.OriginalUriBaseIds ?? new Dictionary<string, ArtifactLocation>();
_run.OriginalUriBaseIds ??= new Dictionary<string, ArtifactLocation>();

foreach (string key in _originalUriBaseIds.Keys)
{
Expand Down Expand Up @@ -98,7 +100,7 @@ public override PhysicalLocation VisitPhysicalLocation(PhysicalLocation node)
Region expandedRegion;
ArtifactLocation artifactLocation = node.ArtifactLocation;

_fileRegionsCache = _fileRegionsCache ?? new FileRegionsCache();
_fileRegionsCache ??= new FileRegionsCache();

if (artifactLocation.Uri == null && artifactLocation.Index >= 0)
{
Expand Down Expand Up @@ -276,10 +278,11 @@ private ArtifactLocation ExpressRelativeToRepoRoot(ArtifactLocation node)
if (repoRootPath != null)
{
var repoRootUri = new Uri(repoRootPath + @"\", UriKind.Absolute);

_repoRootUris ??= new HashSet<Uri>();
_repoRootUris.Add(repoRootUri);

Uri repoRelativeUri = repoRootUri.MakeRelativeUri(uri);
node.Uri = repoRelativeUri;
node.Uri = repoRootUri.MakeRelativeUri(uri);
node.UriBaseId = GetUriBaseIdForRepoRoot(repoRootUri);
}
}
Expand Down