Skip to content

Commit

Permalink
Merge pull request #589 from NetSparkleUpdater/fix/588
Browse files Browse the repository at this point in the history
Fix app cast bug; some versions not read properly
  • Loading branch information
Deadpikle authored Jul 1, 2024
2 parents e0f7791 + 93ab29d commit 33c0c89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/NetSparkle.Tests.AppCastGenerator/AppCastMakerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ public void CanGetVersionFromName()
Assert.Equal("99999999999999999999999.999999999999999999.99999999999999999", AppCastMaker.GetVersionFromName("app 99999999999999999999999.999999999999999999.99999999999999999.txt"));
Assert.Equal("1.0.0-0A.is.legal", AppCastMaker.GetVersionFromName("app 1.0.0-0A.is.legal.txt"));

// #588
Assert.Equal("2.10.1", AppCastMaker.GetVersionFromName("appsetup-2.10.1.exe"));
Assert.Equal("2.10.1", AppCastMaker.GetVersionFromName("appsetup_2.10.1.exe"));
Assert.Equal("2.10.1", AppCastMaker.GetVersionFromName("appsetup 2.10.1.exe"));
Assert.Equal("2.10.1", AppCastMaker.GetVersionFromName("appsetup2.10.1.exe"));

// Invalid semantic versions tests
Assert.Null(AppCastMaker.GetVersionFromName("app 1.2.3-0123.txt"));
Assert.Null(AppCastMaker.GetVersionFromName("app 1.2.3-0123.0123.txt"));
Expand Down
16 changes: 9 additions & 7 deletions src/NetSparkle.Tools.AppCastGenerator/AppCastMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ private static bool ContainsValidVersionInfo(string segment)
return Regex.IsMatch(segment, simpleVersionPattern) || Regex.IsMatch(segment, semverPattern);
}

// This regex finds the first text block that is not preceded by a + or - and is followed by a number (starting from left)
// This regex finds the first text block that is not preceded by a + or -
// and is followed by a number (starting from left)
private static string RemoveTextBlockFromLeft(string input)
{
if (!Regex.IsMatch(input, @"\d"))
Expand Down Expand Up @@ -94,7 +95,10 @@ private static string RemoveTextBlockFromLeft(string input)
}
}

// This regex finds the first text block that is not preceded by a + or - and is followed by a number (starting from right)
// This regex finds the first text block that is not preceded
// by a + or - and is followed by a number (starting from right)
// TODO: this func and RemoveTextBlockFromLeft need renaming and
// clarifying; docs are not too great here and may be swapping left/right
private static string RemoveTextBlockFromRight(string input)
{
var match = Regex.Match(input, @"(?<![a-zA-Z+-])[a-zA-Z]+(?=\d)");
Expand All @@ -117,9 +121,10 @@ private static string SplitOnPeriodsAndFindVersion(string part)
for (int i = segments.Length - 1; i >= 0; i--)
{
var segment = segments[i];
// if segment has text in it at the start and digits later, get rid of text and +/- symbol
if (Regex.IsMatch(segment, @"[a-zA-Z]") && Regex.IsMatch(segment, @"\d"))
{
var match = Regex.Match(segment, @"[^+-]*[a-zA-Z]");
var match = Regex.Match(segment, @"[^+-]*[a-zA-Z][+-]?");
if (match.Success)
{
segment = segment.Substring(match.Index + match.Length);
Expand Down Expand Up @@ -148,11 +153,8 @@ private static string FindVersionInfoInString(string str, bool removeTextFromLef
string lastValidVersion = null;
if (!string.IsNullOrEmpty(str))
{
// Remove any text block from left
// For example 0.1foo becomes 0.1, 0.1-foo stays 0.1-foo, 0.1+foo stays 0.1+foo
str = removeTextFromLeft ? RemoveTextBlockFromLeft(str) : RemoveTextBlockFromRight(str);

// Make sure left part has a number
// Make sure part has a number
if (Regex.IsMatch(str, @"\d"))
{
// Check if it has only numeric values and a simple version for quick check
Expand Down

0 comments on commit 33c0c89

Please sign in to comment.