@@ -490,76 +490,79 @@ public static bool TryConvertFromXml(
490
490
{
491
491
Hashtable metadata = new Hashtable ( StringComparer . InvariantCultureIgnoreCase ) ;
492
492
493
- var childNodes = entry . ChildNodes ;
494
- foreach ( XmlElement child in childNodes )
493
+ var entryChildNodes = entry . ChildNodes ;
494
+ foreach ( XmlElement entryChild in entryChildNodes )
495
495
{
496
- var key = child . LocalName ;
497
- var value = child . InnerText ;
496
+ var entryKey = entryChild . LocalName ;
498
497
499
- if ( key . Equals ( "Title" ) )
498
+ // For repositories such as JFrog's Artifactory, there is no 'Id' property, just 'title' (which contains the name of the pkg).
499
+ // However, other repos, like PSGallery include the name of the pkg in the 'Id' property and leave 'title' empty.
500
+ // In JFrog's Artifactory, 'title' exists both as a child of the 'entry' node and as a child of the 'properties' node,
501
+ // though sometimes 'title' under the 'properties' node can be empty (so default to using the former).
502
+ if ( entryKey . Equals ( "title" ) )
500
503
{
501
- // For repositories such as JFrog's Artifactory, there is no 'Id' property, just 'Title' (which contains the name of the pkg).
502
- // However, other repos, like PSGallery include the name of the pkg in the 'Id' property and leave 'Title' empty.
503
-
504
- // First check to see that both 'Title' and 'Id' exist in the child nodes.
505
- // If both exist, take 'Id', otherwise just take 'Title'.
506
- bool containsID = false ;
507
- foreach ( XmlElement childNode in childNodes )
504
+ metadata [ "Id" ] = entryChild . InnerText ;
505
+ }
506
+ else if ( entryKey . Equals ( "properties" ) )
507
+ {
508
+ var propertyChildNodes = entryChild . ChildNodes ;
509
+ foreach ( XmlElement propertyChild in propertyChildNodes )
508
510
{
509
- if ( childNode . LocalName == "Id" )
511
+ var propertyKey = propertyChild . LocalName ;
512
+ var propertyValue = propertyChild . InnerText ;
513
+
514
+ if ( propertyKey . Equals ( "Title" ) )
510
515
{
511
- containsID = true ;
516
+ if ( ! metadata . ContainsKey ( "Id" ) )
517
+ {
518
+ metadata [ "Id" ] = propertyValue ;
519
+ }
512
520
}
513
- }
521
+ if ( propertyKey . Equals ( "Version" ) )
522
+ {
523
+ metadata [ propertyKey ] = ParseHttpVersion ( propertyValue , out string prereleaseLabel ) ;
524
+ metadata [ "Prerelease" ] = prereleaseLabel ;
525
+ }
526
+ else if ( propertyKey . EndsWith ( "Url" ) )
527
+ {
528
+ metadata [ propertyKey ] = ParseHttpUrl ( propertyValue ) as Uri ;
529
+ }
530
+ else if ( propertyKey . Equals ( "Tags" ) )
531
+ {
532
+ metadata [ propertyKey ] = propertyValue . Split ( new char [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
533
+ }
534
+ else if ( propertyKey . Equals ( "Published" ) )
535
+ {
536
+ metadata [ propertyKey ] = ParseHttpDateTime ( propertyValue ) ;
537
+ }
538
+ else if ( propertyKey . Equals ( "Dependencies" ) )
539
+ {
540
+ metadata [ propertyKey ] = ParseHttpDependencies ( propertyValue ) ;
541
+ }
542
+ else if ( propertyKey . Equals ( "IsPrerelease" ) )
543
+ {
544
+ bool . TryParse ( propertyValue , out bool isPrerelease ) ;
514
545
515
- if ( ! containsID )
516
- {
517
- metadata [ "Id" ] = value ;
518
- }
519
- }
520
- if ( key . Equals ( "Version" ) )
521
- {
522
- metadata [ key ] = ParseHttpVersion ( value , out string prereleaseLabel ) ;
523
- metadata [ "Prerelease" ] = prereleaseLabel ;
524
- }
525
- else if ( key . EndsWith ( "Url" ) )
526
- {
527
- metadata [ key ] = ParseHttpUrl ( value ) as Uri ;
528
- }
529
- else if ( key . Equals ( "Tags" ) )
530
- {
531
- metadata [ key ] = value . Split ( new char [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
532
- }
533
- else if ( key . Equals ( "Published" ) )
534
- {
535
- metadata [ key ] = ParseHttpDateTime ( value ) ;
536
- }
537
- else if ( key . Equals ( "Dependencies" ) )
538
- {
539
- metadata [ key ] = ParseHttpDependencies ( value ) ;
540
- }
541
- else if ( key . Equals ( "IsPrerelease" ) )
542
- {
543
- bool . TryParse ( value , out bool isPrerelease ) ;
546
+ metadata [ propertyKey ] = isPrerelease ;
547
+ }
548
+ else if ( propertyKey . Equals ( "NormalizedVersion" ) )
549
+ {
550
+ if ( ! NuGetVersion . TryParse ( propertyValue , out NuGetVersion parsedNormalizedVersion ) )
551
+ {
552
+ errorMsg = string . Format (
553
+ CultureInfo . InvariantCulture ,
554
+ @"TryReadPSGetInfo: Cannot parse NormalizedVersion" ) ;
544
555
545
- metadata [ key ] = isPrerelease ;
546
- }
547
- else if ( key . Equals ( "NormalizedVersion" ) )
548
- {
549
- if ( ! NuGetVersion . TryParse ( value , out NuGetVersion parsedNormalizedVersion ) )
550
- {
551
- errorMsg = string . Format (
552
- CultureInfo . InvariantCulture ,
553
- @"TryReadPSGetInfo: Cannot parse NormalizedVersion" ) ;
556
+ parsedNormalizedVersion = new NuGetVersion ( "1.0.0.0" ) ;
557
+ }
554
558
555
- parsedNormalizedVersion = new NuGetVersion ( "1.0.0.0" ) ;
559
+ metadata [ propertyKey ] = parsedNormalizedVersion ;
560
+ }
561
+ else
562
+ {
563
+ metadata [ propertyKey ] = propertyValue ;
564
+ }
556
565
}
557
-
558
- metadata [ key ] = parsedNormalizedVersion ;
559
- }
560
- else
561
- {
562
- metadata [ key ] = value ;
563
566
}
564
567
}
565
568
0 commit comments