Fix: adding conditional operator to prevent NullReferenceException in NugetComponentDetector (#492)

* adding conditional operator for name and version variables

* check that component name is not null

* fix: log message

---------

Co-authored-by: Daniel Akili <danielakili@microsoft.com>
Co-authored-by: Justin Perez <justinperez@microsoft.com>
This commit is contained in:
Daniel Akili 2023-03-30 15:19:51 -07:00 коммит произвёл GitHub
Родитель 1aba67efcf
Коммит a5fc322dca
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

@ -119,11 +119,18 @@ public class NuGetComponentDetector : FileComponentDetector
XmlNode packageNode = doc["package"];
XmlNode metadataNode = packageNode["metadata"];
var name = metadataNode["id"].InnerText;
var version = metadataNode["version"].InnerText;
var name = metadataNode["id"]?.InnerText;
var version = metadataNode["version"]?.InnerText;
var authors = metadataNode["authors"]?.InnerText.Split(",").Select(author => author.Trim()).ToArray();
if (name == null)
{
this.Logger.LogInformation("Could not parse name from Nuspec {NuspecLocation}", stream.Location);
singleFileComponentRecorder.RegisterPackageParseFailure(stream.Location);
return;
}
if (!NuGetVersion.TryParse(version, out var parsedVer))
{
this.Logger.LogInformation("Version '{NuspecVersion}' from {NuspecLocation} could not be parsed as a NuGet version", version, stream.Location);