semver
semver copied to clipboard
NewConstraint method faulty behavior
Used version: 3.1.1 When I try to create a constraint with NewConstraint method I get following returns:
good Example c, cErr := semver.NewConstraint("12.3.4.1234") c.String() = nil cErr = "improper constraint: 12.3.4.1234"
faulty behavior c, cErr := semver.NewConstraint("12.23.4.1234") c.String() = "12.23.4 1234" cErr = nil
or
c, cErr := semver.NewConstraint("12.3.34.1234") c.String() = "12.3.34 1234" cErr = nil
I would expect the same behavior as with "12.3.4.1234", means telling me its not a contraint..
FYI: the used regex to validate the contstraint fails: https://regex101.com/r/3fEGeK/1
I can explain what's going on here. 12.3.4.1234
is invalid because it has 4 parts and semver is only 3 parts.
12.3.34 1234
is read as 2 separate constraints. 12.3.34
and 1234
. Those are added together. See https://github.com/Masterminds/semver#basic-comparisons
Ah I'm sorry, had to correct the 2 faulty examples, there were copy paste typos. Is this: c, cErr := semver.NewConstraint("12.23.4.1234") c.String() = "12.23.4 1234" cErr = nil
expected behavior? Its a non semver string with 4 parts like in the first example, but handled differently. The third dot is removed and its a valid range? I would expect an error here.
Wy is 12.3.4.1234 and 12.23.4.1234 handled differently? the only difference is that the second part is 2 digits
I have verified the issue. https://go.dev/play/p/wMEsKXb5KEx
@benjaminbear The fix can be found in #186 and the commit message explains what happened to cause this.
I am planning on getting a new release out by the end of this week with some fixes and new functionality.
Feel free to double check my fix and tell me if it didn't work.
Great to hear! Thank you very much @mattfarina