Skip to content

Commit

Permalink
Ignore leading and trailing spaces on versions (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfiorenzano authored Mar 6, 2024
1 parent 1eea9ac commit 5be8728
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ private static bool VersionValidForSpec(string version, string spec)
}

var op = spec[..i];
var specVerSection = spec[i..].Trim();

var targetVer = PythonVersion.Create(version);
var specVer = PythonVersion.Create(spec[i..]);
var specVer = PythonVersion.Create(specVerSection);

if (!targetVer.Valid)
{
Expand All @@ -106,7 +107,7 @@ private static bool VersionValidForSpec(string version, string spec)

if (!specVer.Valid)
{
throw new ArgumentException($"The version specification {spec[i..]} is not a valid python version");
throw new ArgumentException($"The version specification {specVerSection} is not a valid python version");
}

return op switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void TestVersionValidForSpec()
IList<(IList<string>, IList<string>, IList<string>)> testCases = new List<(IList<string>, IList<string>, IList<string>)>
{
(new List<string> { "==1.0" }, new List<string> { "1.0" }, new List<string> { "1.0.1", "2.0", "0.1" }),
(new List<string> { "== 1.0 " }, new List<string> { "1.0" }, new List<string> { "1.0.1", "2.0", "0.1" }),
(new List<string> { "==1.4.*" }, new List<string> { "1.4", "1.4.1", "1.4.2", "1.4.3" }, new List<string> { "1.0.1", "2.0", "0.1", "1.5", "1.5.0" }),
(new List<string> { ">=1.0" }, new List<string> { "1.0", "1.1", "1.5" }, new List<string> { "0.9" }),
(new List<string> { ">=1.0", "<=1.4" }, new List<string> { "1.0", "1.1", "1.4" }, new List<string> { "0.9", "1.5" }),
Expand Down

0 comments on commit 5be8728

Please sign in to comment.