Skip to content

fix: ensure caret wildcard ^* matches any version as documented - #321

Closed
AdamMagued wants to merge 1 commit into
Masterminds:masterfrom
AdamMagued:fix-caret-wildcard-constraint
Closed

AdamMagued wants to merge 1 commit into
Masterminds:masterfrom
AdamMagued:fix-caret-wildcard-constraint

Conversation

@AdamMagued

Copy link
Copy Markdown

Summary

The comment documenting caret constraint behavior in constraints.go specifies:

^* --> (any)

However, parseConstraint normalizes wildcard segments to 0.0.0 while marking dirty = true and leaving minorDirty and patchDirty as false. In constraintCaret, execution subsequently fell through to the patch-level equality check eq = c.con.Patch() == v.Patch(), restricting ^* (as well as ^x and ^X) to matching only 0.0.0.

Changes

  • In constraintCaret, check if the constraint has c.dirty && !c.minorDirty && !c.patchDirty after validating the prerelease policy. When true, return true, nil to match any version as documented.
  • Exact ^0.0.0 constraints have dirty == false and continue through to the patch equality check (>= 0.0.0 < 0.0.1), preserving existing semantics.
  • Added regression tests in constraints_test.go verifying ^*, ^x, and ^X match versions like 1.2.3, 0.1.0, etc., while ensuring ^0.0.0 only matches 0.0.0.

Fixes #317

The documentation for caret constraints specifies that ^* matches any version (^* --> (any)). However, parseConstraint normalizes wildcard segments to 0.0.0 while setting dirty = true and keeping minorDirty and patchDirty false. In constraintCaret, execution subsequently fell through to the patch-level equality check, restricting ^* to matching only 0.0.0.

Add a check in constraintCaret for dirty version constraints with neither minor nor patch marked dirty (c.dirty && !c.minorDirty && !c.patchDirty) to match any version as documented, while preserving the existing exact ^0.0.0 behavior. Add regression test cases in constraints_test.go.

Fixes Masterminds#317
@AdamMagued

Copy link
Copy Markdown
Author

Closing in favor of earlier community PR #319 to avoid duplicate review effort.

@AdamMagued AdamMagued closed this Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Caret wildcard ^* is documented as matching any version but only matches 0.0.0

1 participant