Skip to content

Commit

Permalink
Do not emit a warning when patch version ends with .99
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Aug 3, 2023
1 parent b19e476 commit 33e4e46
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
13 changes: 12 additions & 1 deletion store.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,20 @@ func (s *PHPStore) BestVersionForDir(dir string) (*Version, string, string, erro
func (s *PHPStore) bestVersion(versionPrefix, source string) (*Version, string, string, error) {
warning := ""

isPatchVersion := false
pos := strings.LastIndexByte(versionPrefix, '.')
if pos != strings.IndexByte(versionPrefix, '.') {
if "99" == versionPrefix[pos+1:] {
versionPrefix = versionPrefix[:pos]
pos = strings.LastIndexByte(versionPrefix, '.')
} else {
isPatchVersion = true
}
}

// Check if versionPrefix is actually a patch version, if so first do an
// exact match lookup and fallback to a minor version check
if pos := strings.LastIndexByte(versionPrefix, '.'); pos != strings.IndexByte(versionPrefix, '.') {
if isPatchVersion {
// look for an exact match, the order does not matter here
for _, v := range s.versions {
if v.Version == versionPrefix {
Expand Down
11 changes: 11 additions & 0 deletions store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,15 @@ func TestBestVersion(t *testing.T) {
t.Error("8.0.10 requirement should trigger a warning")
}
}

{
bestVersion, _, warning, _ := store.bestVersion("8.0.99", "testing")
if bestVersion == nil {
t.Error("8.0.99 requirement should find a best version")
} else if bestVersion.Version != "8.0.27" {
t.Error("8.0.99 requirement should find 8.0.27 as best version")
} else if warning != "" {
t.Error("8.0.99 requirement should not trigger a warning")
}
}
}

0 comments on commit 33e4e46

Please sign in to comment.