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:
Родитель
1aba67efcf
Коммит
a5fc322dca
|
@ -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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче