Masterminds / semver

Work with Semantic Versions in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Caret operator (^) gives unexpected results when the minor version in constraint is 0(zero)

arshchimni opened this issue · comments

Hi Community.
Thank you for this helpful library.
I came across an issue today with the latest version while implementing the following constraint

"^0.0.1"

According to the docs, this should exactly match only the 0.0.1 version and nothing else.
But it matches any minor version update as long as the patch is 1, ie; if we pass 0.3.1 the above constraint passes, but 0.3.0 fails.

This happens because we do not check for the case when the minor version is set to 0(zero) in a caret constraint defined in the function

func constraintCaret(v *Version, c *constraint) (bool, error) {

Go Playground link -> https://go.dev/play/p/mO_fog7Cyc2