Skip to content

Commit a363f67

Browse files
authored
bug: fix int out of bounds for branch names with long numbers (#612)
1 parent 6c390d2 commit a363f67

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Models/NumericSort.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,16 @@ public static int Compare(string s1, string s2)
5151
int result;
5252
if (isDigit1 && isDigit2)
5353
{
54-
int num1 = int.Parse(sub1);
55-
int num2 = int.Parse(sub2);
56-
result = num1 - num2;
54+
// compare numeric values
55+
if (sub1.Length == sub2.Length)
56+
{
57+
// if length is the same, lexicographical comparison is good also for numbers
58+
result = string.CompareOrdinal(sub1, sub2);
59+
}
60+
else
61+
{
62+
result = sub1.Length.CompareTo(sub2.Length);
63+
}
5764
}
5865
else
5966
{

0 commit comments

Comments
 (0)