Skip to content

Commit 71129bc

Browse files
author
José Valim
committed
Merge pull request #1683 from meh/fix-version
Fix handling pre/build data when minor/patch is missing in Mix.Version
2 parents 654988f + a107b2b commit 71129bc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/mix/lib/mix/version.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,17 @@ defmodule Mix.Version do
277277
end
278278
end
279279
280+
defp nillify(""), do: nil
281+
defp nillify(o), do: o
282+
280283
@spec parse_version(String.t) :: { :ok, Mix.Version.matchable } | { :error, :invalid_version }
281284
def parse_version(string) when is_binary(string) do
282285
if valid_version?(string) do
283286
destructure [_, major, minor, patch, pre], Regex.run(@version_regex, string)
284287
285288
major = binary_to_integer(major)
286-
minor = binary_to_integer(minor || "0")
287-
patch = binary_to_integer(patch || "0")
289+
minor = binary_to_integer(minor |> nillify || "0")
290+
patch = binary_to_integer(patch |> nillify || "0")
288291
pre = pre && parse_pre(pre) || []
289292

290293
{ :ok, { major, minor, patch, pre } }

lib/mix/test/mix/version_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ defmodule Mix.VersionTest do
2323
refute P.valid_requirement?(P.lexer("& 1.0.0", []))
2424
end
2525

26+
test :parse do
27+
assert V.Schema[major: 1, minor: 0, patch: 0] = V.parse("1")
28+
assert V.Schema[major: 1, minor: 2, patch: 0] = V.parse("1.2")
29+
assert V.Schema[major: 1, minor: 2, patch: 3] = V.parse("1.2.3")
30+
assert V.Schema[major: 1, minor: 4, patch: 0, pre: "5-g3318bd5"] = V.parse("1.4-5-g3318bd5")
31+
end
32+
2633
test :== do
2734
assert V.match?("2.3", "2.3")
2835
refute V.match?("2.4", "2.3")

0 commit comments

Comments
 (0)