From 8b72b035d16817bacf3c31e61899cfb82b5390ee Mon Sep 17 00:00:00 2001 From: Andrew Nesbitt Date: Thu, 29 Jan 2026 14:03:57 +0000 Subject: [PATCH] Preserve v prefix for Go versions --- constraint.go | 19 +++++++++++++++++-- parser.go | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/constraint.go b/constraint.go index 4d0937b..408d11d 100644 --- a/constraint.go +++ b/constraint.go @@ -19,11 +19,20 @@ type Constraint struct { // ParseConstraint parses a constraint string into a Constraint. func ParseConstraint(s string) (*Constraint, error) { + return parseConstraintWithScheme(s, "") +} + +// parseConstraintWithScheme parses a constraint with scheme-specific handling. +// For Go/golang schemes, the v prefix is preserved. +func parseConstraintWithScheme(s, scheme string) (*Constraint, error) { s = strings.TrimSpace(s) if s == "" { return nil, fmt.Errorf("empty constraint") } + // Go versions preserve the v prefix + preserveVPrefix := scheme == "go" || scheme == "golang" + matches := operatorRegex.FindStringSubmatch(s) if matches != nil { operator := matches[1] @@ -31,12 +40,18 @@ func ParseConstraint(s string) (*Constraint, error) { if version == "" { return nil, fmt.Errorf("invalid constraint format: %s", s) } - version = stripVPrefix(version) + if !preserveVPrefix { + version = stripVPrefix(version) + } return &Constraint{Operator: operator, Version: version}, nil } // No operator found, treat as exact match - return &Constraint{Operator: "=", Version: stripVPrefix(s)}, nil + version := s + if !preserveVPrefix { + version = stripVPrefix(s) + } + return &Constraint{Operator: "=", Version: version}, nil } // stripVPrefix removes a leading 'v' or 'V' from version strings. diff --git a/parser.go b/parser.go index 52d5db7..57cbfac 100644 --- a/parser.go +++ b/parser.go @@ -181,7 +181,7 @@ func (p *Parser) parseConstraints(constraintsStr, scheme string) (*Range, error) continue } - constraint, err := ParseConstraint(part) + constraint, err := parseConstraintWithScheme(part, scheme) if err != nil { return nil, err } @@ -630,7 +630,7 @@ func (p *Parser) parseGoRange(s string) (*Range, error) { parts := strings.Split(s, ",") var result *Range for _, part := range parts { - constraint, err := ParseConstraint(strings.TrimSpace(part)) + constraint, err := parseConstraintWithScheme(strings.TrimSpace(part), "go") if err != nil { return nil, err }