Skip to content

Commit 02708ab

Browse files
committed
use SemanticVersion.CompareTo()
1 parent aa2f23f commit 02708ab

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/code/V2ResponseUtil.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public XmlNode[] ConvertResponseToXML(string httpResponse) {
7575
NuGetVersion emptyVersion = new NuGetVersion("0.0.0.0");
7676
NuGetVersion firstVersion = emptyVersion;
7777
NuGetVersion lastVersion = emptyVersion;
78+
bool shouldFixOrder = true;
7879

7980
//Create the XmlDocument.
8081
XmlDocument doc = new XmlDocument();
@@ -102,7 +103,8 @@ public XmlNode[] ConvertResponseToXML(string httpResponse) {
102103
{
103104
if (!NuGetVersion.TryParse(propertyValue, out NuGetVersion parsedNormalizedVersion))
104105
{
105-
parsedNormalizedVersion = emptyVersion;
106+
// if a version couldn't be parsed, keep ordering as is.
107+
shouldFixOrder = false;
106108
}
107109

108110
if (i == 0)
@@ -124,9 +126,9 @@ public XmlNode[] ConvertResponseToXML(string httpResponse) {
124126
}
125127
}
126128

127-
// only order the array in desc order if array has more than 1 element and is currently in ascending order
128-
// check for emptyVersion is in case a version that couldn't be parsed was found, just keep ordering as is.
129-
if (nodes.Length > 1 && firstVersion != emptyVersion && lastVersion != emptyVersion && firstVersion < lastVersion)
129+
// order the array in descending order if not already.
130+
// check for emptyVersion is in case a version that couldn't be parsed was found for the firstVersion we set it to 0.0.0.0 and that messes up compareTo(), so just keep ordering as is.
131+
if (shouldFixOrder && firstVersion.CompareTo(lastVersion) < 0)
130132
{
131133
nodes = nodes.Reverse().ToArray();
132134
}

0 commit comments

Comments
 (0)