Merge pull request #1683 from meh/fix-version
Fix handling pre/build data when minor/patch is missing in Mix.Version
This commit is contained in:
@@ -277,14 +277,17 @@ defmodule Mix.Version do
|
||||
end
|
||||
end
|
||||
|
||||
defp nillify(""), do: nil
|
||||
defp nillify(o), do: o
|
||||
|
||||
@spec parse_version(String.t) :: { :ok, Mix.Version.matchable } | { :error, :invalid_version }
|
||||
def parse_version(string) when is_binary(string) do
|
||||
if valid_version?(string) do
|
||||
destructure [_, major, minor, patch, pre], Regex.run(@version_regex, string)
|
||||
|
||||
major = binary_to_integer(major)
|
||||
minor = binary_to_integer(minor || "0")
|
||||
patch = binary_to_integer(patch || "0")
|
||||
minor = binary_to_integer(minor |> nillify || "0")
|
||||
patch = binary_to_integer(patch |> nillify || "0")
|
||||
pre = pre && parse_pre(pre) || []
|
||||
|
||||
{ :ok, { major, minor, patch, pre } }
|
||||
|
||||
@@ -23,6 +23,13 @@ defmodule Mix.VersionTest do
|
||||
refute P.valid_requirement?(P.lexer("& 1.0.0", []))
|
||||
end
|
||||
|
||||
test :parse do
|
||||
assert V.Schema[major: 1, minor: 0, patch: 0] = V.parse("1")
|
||||
assert V.Schema[major: 1, minor: 2, patch: 0] = V.parse("1.2")
|
||||
assert V.Schema[major: 1, minor: 2, patch: 3] = V.parse("1.2.3")
|
||||
assert V.Schema[major: 1, minor: 4, patch: 0, pre: "5-g3318bd5"] = V.parse("1.4-5-g3318bd5")
|
||||
end
|
||||
|
||||
test :== do
|
||||
assert V.match?("2.3", "2.3")
|
||||
refute V.match?("2.4", "2.3")
|
||||
|
||||
Reference in New Issue
Block a user