@@ -56,7 +56,8 @@ func (v *Version) Metadata() string {
5656}
5757
5858// String returns the string representation, in the format:
59- // "v1.2.3-beta+md"
59+ //
60+ // "v1.2.3-beta+md"
6061func (v Version ) String () string {
6162 var b bytes.Buffer
6263 fmt .Fprintf (& b , "v%d.%d.%d" , v .major , v .minor , v .patch )
@@ -73,22 +74,25 @@ func (v Version) String() string {
7374// of the form "vMAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]". This
7475// conforms to https://semver.org/spec/v2.0.0.html
7576var versionRE = regexp .MustCompile (
76- `^ v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-.]+)?(\+[0-9A-Za-z-.]+|)?$ ` ,
77+ `v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-.]+)?(\+[0-9A-Za-z-.]+|)?` ,
7778 // ^major ^minor ^patch ^preRelease ^metadata
7879)
7980
8081// numericRE is the regexp used to check if an identifier is numeric.
8182var numericRE = regexp .MustCompile (`^(0|[1-9][0-9]*)$` )
8283
83- // Parse creates a version from a string. The string must be a valid semantic
84+ // Parse creates a version from a string. The string must contain a valid semantic
8485// version (as per https://semver.org/spec/v2.0.0.html) in the format:
85- // "vMINOR.MAJOR.PATCH[-PRERELEASE][+METADATA]".
86+ //
87+ // "vMINOR.MAJOR.PATCH[-PRERELEASE][+METADATA]".
88+ //
8689// MINOR, MAJOR, and PATCH are numeric values (without any leading 0s).
8790// PRERELEASE and METADATA can contain ASCII characters and digits, hyphens and
8891// dots.
89- func Parse (str string ) (* Version , error ) {
90- if ! versionRE .MatchString (str ) {
91- return nil , errors .Errorf ("invalid version string '%s'" , str )
92+ func Parse (fullStr string ) (* Version , error ) {
93+ var str string
94+ if str = versionRE .FindString (str ); len (str ) == 0 {
95+ return nil , errors .Errorf ("invalid version string '%s'" , fullStr )
9296 }
9397
9498 var v Version
0 commit comments