Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from matfax/leading-zero
Browse files Browse the repository at this point in the history
feat: let ParseTolerant remove leading zeros from version digits
  • Loading branch information
matfax authored Jan 12, 2019
2 parents 8974d02 + d58a79c commit b182ca4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ func ParseTolerant(s string) (Version, error) {
parts := strings.SplitN(s, ".", 3)
// Remove leading zeros.
for i, p := range parts {
parts[i] = strings.TrimPrefix(p, "0")
if len(p) > 1 {
parts[i] = strings.TrimPrefix(p, "0")
}
}
// Fill up shortened versions.
if len(parts) < 3 {
Expand Down
1 change: 1 addition & 0 deletions semver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var tolerantFormatTests = []formatTest{
{Version{1, 2, 3, nil, nil}, "v1.2.3"},
{Version{1, 2, 3, nil, nil}, " 1.2.3 "},
{Version{1, 2, 3, nil, nil}, "01.02.03"},
{Version{0, 0, 3, nil, nil}, "00.0.03"},
{Version{1, 2, 0, nil, nil}, "1.2"},
{Version{1, 0, 0, nil, nil}, "1"},
}
Expand Down

0 comments on commit b182ca4

Please sign in to comment.