{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-lang/elixir/issues/4407","repository_url":"https://api.github.com/repos/elixir-lang/elixir","labels_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4407/labels{/name}","comments_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4407/comments","events_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4407/events","html_url":"https://github.com/elixir-lang/elixir/issues/4407","id":142022408,"number":4407,"title":"Incorrect SemVer validation on metadata","user":{"login":"pdilyard","id":1459456,"avatar_url":"https://avatars.githubusercontent.com/u/1459456?v=3","gravatar_id":"","url":"https://api.github.com/users/pdilyard","html_url":"https://github.com/pdilyard","followers_url":"https://api.github.com/users/pdilyard/followers","following_url":"https://api.github.com/users/pdilyard/following{/other_user}","gists_url":"https://api.github.com/users/pdilyard/gists{/gist_id}","starred_url":"https://api.github.com/users/pdilyard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdilyard/subscriptions","organizations_url":"https://api.github.com/users/pdilyard/orgs","repos_url":"https://api.github.com/users/pdilyard/repos","events_url":"https://api.github.com/users/pdilyard/events{/privacy}","received_events_url":"https://api.github.com/users/pdilyard/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elixir-lang/elixir/labels/App:Elixir","name":"App:Elixir","color":"CCCCCC"},{"url":"https://api.github.com/repos/elixir-lang/elixir/labels/Kind:Bug","name":"Kind:Bug","color":"e10c02"},{"url":"https://api.github.com/repos/elixir-lang/elixir/labels/Level:Intermediate","name":"Level:Intermediate","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/elixir-lang/elixir/milestones/17","html_url":"https://github.com/elixir-lang/elixir/milestones/v1.3.0","labels_url":"https://api.github.com/repos/elixir-lang/elixir/milestones/17/labels","id":1442016,"number":17,"title":"v1.3.0","description":"","creator":{"login":"josevalim","id":9582,"avatar_url":"https://avatars.githubusercontent.com/u/9582?v=3","gravatar_id":"","url":"https://api.github.com/users/josevalim","html_url":"https://github.com/josevalim","followers_url":"https://api.github.com/users/josevalim/followers","following_url":"https://api.github.com/users/josevalim/following{/other_user}","gists_url":"https://api.github.com/users/josevalim/gists{/gist_id}","starred_url":"https://api.github.com/users/josevalim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josevalim/subscriptions","organizations_url":"https://api.github.com/users/josevalim/orgs","repos_url":"https://api.github.com/users/josevalim/repos","events_url":"https://api.github.com/users/josevalim/events{/privacy}","received_events_url":"https://api.github.com/users/josevalim/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":7,"state":"open","created_at":"2015-12-03T12:25:01Z","updated_at":"2016-03-19T08:18:07Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2016-03-19T03:21:53Z","updated_at":"2016-03-19T09:40:42Z","closed_at":null,"body":"### Environment\r\n\r\n* Elixir version (elixir -v): 1.2.2\r\n* Operating system: Mac OSX\r\n\r\n### Current behavior\r\n\r\nI have versioning in my project set up to use the git SHA in the version number, for example `0.0.1+sha.d1af69c`. Here's the function that generates this:\r\n\r\n```\r\n  defp full_version(sem_ver) do\r\n    {result, _exit_code} = System.cmd(\"git\", [\"rev-parse\", \"HEAD\"])\r\n    sha = String.slice(result, 0, 7)\r\n    \"#{sem_ver}+sha.#{sha}\"\r\n  end\r\n```\r\n\r\nBy chance, I got a commit hash where the first 7 characters were all numbers, and where the first number was 0, so my full version number should be: `0.0.1+sha.0702245`. However this raises the following error:\r\n\r\n```\r\n** (Mix) Expected :version to be a SemVer version\r\n```\r\n\r\n### Expected behavior\r\n\r\nBy my understanding of the SemVer spec, numeric prerelease versions after a hyphen cannot begin with a leading 0 (see http://semver.org/#spec-item-9).\r\n\r\nHowever, metadata coming after a plus sign do not have this limitation, see: http://semver.org/#spec-item-10.\r\n\r\nI believe this error was thrown due to incorrect SemVer validation.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/elixir-lang/elixir/issues/comments/198675118","html_url":"https://github.com/elixir-lang/elixir/issues/4407#issuecomment-198675118","issue_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4407","id":198675118,"user":{"login":"whatyouhide","id":3890250,"avatar_url":"https://avatars.githubusercontent.com/u/3890250?v=3","gravatar_id":"","url":"https://api.github.com/users/whatyouhide","html_url":"https://github.com/whatyouhide","followers_url":"https://api.github.com/users/whatyouhide/followers","following_url":"https://api.github.com/users/whatyouhide/following{/other_user}","gists_url":"https://api.github.com/users/whatyouhide/gists{/gist_id}","starred_url":"https://api.github.com/users/whatyouhide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whatyouhide/subscriptions","organizations_url":"https://api.github.com/users/whatyouhide/orgs","repos_url":"https://api.github.com/users/whatyouhide/repos","events_url":"https://api.github.com/users/whatyouhide/events{/privacy}","received_events_url":"https://api.github.com/users/whatyouhide/received_events","type":"User","site_admin":false},"created_at":"2016-03-19T09:40:42Z","updated_at":"2016-03-19T09:40:42Z","body":"From my research, it looks like the problem is not the leading `0`, it's the `.` in the build metadata. Right now, the regex we're using to parse versions ([here](https://github.com/elixir-lang/elixir/blob/4fb70d9ebf0da297eec295ea1043bab722ae9fe6/lib/elixir/lib/version.ex#L368)) is this:\r\n\r\n```elixir\r\n    @version_regex ~r/^\r\n      (\\d+)                 # major\r\n      (?:\\.(\\d+))?          # minor\r\n      (?:\\.(\\d+))?          # patch\r\n      (?:\\-([\\d\\w\\.\\-]+))?  # pre\r\n      (?:\\+([\\d\\w\\-]+))?    # build\r\n      $/x\r\n```\r\n\r\nAs you can see, `.`s are allowed in the pre info but not in the build info. This is against the SEMVER spec which says (in [section 10](http://semver.org/#spec-item-10)):\r\n\r\n> Build metadata MAY be denoted by appending a plus sign and a series of **dot separated identifiers** [...]\r\n\r\n(emphasis added by me)\r\n\r\nThe leading 0 spec for pre info is actually not enforced by `Version` (as I think it would make the code much more annoying :smile:), but that's a story for another day.\r\n\r\nAnyhow, I pushed a possible fix to #4409, let's see how it goes!"}}