summaryrefslogtreecommitdiff
path: root/vendor/github.com/blang/semver/semver.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-05-20 20:10:51 +0200
committerGitHub <noreply@github.com>2020-05-20 20:10:51 +0200
commitb0bfa0e6da7d1cb0673328cdcff18329ca18cabf (patch)
tree226b022eb0d7aef35ad65dcaa10c6a2ec9f56e7c /vendor/github.com/blang/semver/semver.go
parent09f8f14b4f7d09946d3d5cfc5460ec9923f7da59 (diff)
parentf9c392f50a631a181bc2aa194b9c46504506d657 (diff)
downloadpodman-b0bfa0e6da7d1cb0673328cdcff18329ca18cabf.tar.gz
podman-b0bfa0e6da7d1cb0673328cdcff18329ca18cabf.tar.bz2
podman-b0bfa0e6da7d1cb0673328cdcff18329ca18cabf.zip
Merge pull request #6271 from jwhonce/wip/version
V2 API Version Support
Diffstat (limited to 'vendor/github.com/blang/semver/semver.go')
-rw-r--r--vendor/github.com/blang/semver/semver.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/vendor/github.com/blang/semver/semver.go b/vendor/github.com/blang/semver/semver.go
index bbf85ce97..8ee0842e6 100644
--- a/vendor/github.com/blang/semver/semver.go
+++ b/vendor/github.com/blang/semver/semver.go
@@ -200,6 +200,29 @@ func Make(s string) (Version, error) {
return Parse(s)
}
+// ParseTolerant allows for certain version specifications that do not strictly adhere to semver
+// specs to be parsed by this library. It does so by normalizing versions before passing them to
+// Parse(). It currently trims spaces, removes a "v" prefix, and adds a 0 patch number to versions
+// with only major and minor components specified
+func ParseTolerant(s string) (Version, error) {
+ s = strings.TrimSpace(s)
+ s = strings.TrimPrefix(s, "v")
+
+ // Split into major.minor.(patch+pr+meta)
+ parts := strings.SplitN(s, ".", 3)
+ if len(parts) < 3 {
+ if strings.ContainsAny(parts[len(parts)-1], "+-") {
+ return Version{}, errors.New("Short version cannot contain PreRelease/Build meta data")
+ }
+ for len(parts) < 3 {
+ parts = append(parts, "0")
+ }
+ s = strings.Join(parts, ".")
+ }
+
+ return Parse(s)
+}
+
// Parse parses version string and returns a validated Version or error
func Parse(s string) (Version, error) {
if len(s) == 0 {