Skip to content

Commit 1a4b1cb

Browse files
committed
Fix: Versions.prerelease? must skip metadata
A version number such as `1.0+meta` was considered a prerelease because the metadata contains a letter. We must ignore the metadata part.
1 parent 3084edd commit 1a4b1cb

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/versions.cr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ module Shards
150150
end
151151

152152
def self.prerelease?(str)
153-
str.each_char.any?(&.ascii_letter?)
153+
str.each_char do |char|
154+
return true if char.ascii_letter?
155+
break if char == '+'
156+
end
157+
false
154158
end
155159

156160
protected def self.without_prereleases(versions)

test/versions_test.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ module Shards
1010
assert Versions.prerelease?("1.0.alpha")
1111
assert Versions.prerelease?("1.0.0-rc1")
1212
assert Versions.prerelease?("1.0.0-pre.1.2.x.y")
13+
14+
assert Versions.prerelease?("1.0.0-pre+20190129")
15+
refute Versions.prerelease?("1.0+20190129")
16+
refute Versions.prerelease?("1.0+build1")
1317
end
1418

1519
def test_compare

0 commit comments

Comments
 (0)