Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ parsing the version. For example,

The version object has methods to get the parts of the version, compare it to
other versions, convert the version back into a string, and get the original
string. For more details please see the documentation
string. The zero value of Version represents 0.0.0 and is safe to use without
initialization. For more details please see the documentation
at https://godoc.org/github.com/Masterminds/semver.

# Sorting Semantic Versions
Expand Down
13 changes: 12 additions & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const looseSemVerRegex string = `v?([0-9]+)(\.[0-9]+)?(\.[0-9]+)?` +
`(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?`

// Version represents a single semantic version.
// The zero value of Version represents 0.0.0 and is safe to use without initialization.
type Version struct {
major, minor, patch uint64
pre string
Expand Down Expand Up @@ -338,7 +339,7 @@ func MustParse(v string) *Version {
return sv
}

// String converts a Version object to a string.
// String converts a Version object to a string. For a zero-value Version, this returns "0.0.0".
// Note, if the original version contained a leading v this version will not.
// See the Original() method to retrieve the original value. Semantic Versions
// don't contain a leading v per the spec. Instead it's optional on
Expand All @@ -358,7 +359,17 @@ func (v Version) String() string {
}

// Original returns the original value passed in to be parsed.
// For a zero-value Version, Original returns "0.0.0".
func (v *Version) Original() string {
if v == nil {
return ""
}
if v.original == "" {
if v.major == 0 && v.minor == 0 && v.patch == 0 && v.pre == "" && v.metadata == "" {
return "0.0.0"
}
return v.String()
}
return v.original
}

Expand Down
Loading