Skip to content

~> Constraint Operator Does Not Apply Upper Bound for Major-Only Versions (e.g., “~> 18” includes 19.0.0) #162

Description

@aircraft-cerier

When using the ~> (pessimistic constraint) operator with a major-only version, the upper bound is not correctly enforced.

According to semver convention, a constraint like ~> 18 should translate to:
>= 18.0.0, < 19.0.0
However, the current implementation allows 19.0.0 to match ~> 18, which is unexpected and inconsistent with ~> behavior for more specific version formats like ~> 1.2.3.

✅ Expected Behavior

constraint, _ := version.NewConstraint("~> 18")
v, _ := version.NewVersion("19.0.0")
fmt.Println(constraint.Check(v)) // Expected: false

❌ Actual Behavior

constraint, _ := version.NewConstraint("~> 18")
v, _ := version.NewVersion("19.0.0")
fmt.Println(constraint.Check(v)) // Actual: true ❌

Playground repro: https://go.dev/play/p/wH5SGj61036

🙏 Request

Please fix the parsing logic for ~> constraints to properly enforce the upper bound when only a major version is provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions