Skip to content

Commit

Permalink
fix: trim leading zeros off when comparing numerical components in Ma…
Browse files Browse the repository at this point in the history
…ven versions (#179)
  • Loading branch information
G-Rath authored Mar 9, 2023
1 parent 8eb1a06 commit 8c128a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/semantic/fixtures/maven-versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
1 = 1-0
1 = 1.0-0
1.0 = 1.0-0

1.1 = 1.01

// no separator between number and character
1a = 1-a
1a = 1.0-a
Expand Down
13 changes: 12 additions & 1 deletion pkg/semantic/version-maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,18 @@ func (vt *mavenVersionToken) shouldTrim() bool {
}

func (vt *mavenVersionToken) equal(wt mavenVersionToken) bool {
return vt.prefix == wt.prefix && vt.value == wt.value
if vt.prefix != wt.prefix {
return false
}

vv, vIsNumber := convertToBigInt(vt.value)
wv, wIsNumber := convertToBigInt(wt.value)

if vIsNumber && wIsNumber {
return vv.Cmp(wv) == 0
}

return vt.value == wt.value
}

//nolint:gochecknoglobals // this is read-only and the nicest implementation
Expand Down

0 comments on commit 8c128a0

Please sign in to comment.