Skip to content

Commit

Permalink
fix ^0
Browse files Browse the repository at this point in the history
  • Loading branch information
jhheider authored and mxcl committed Apr 13, 2023
1 parent bad996d commit 61da0e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ export class Range {
v1 = new SemVer(match[2], {tolerant: true})
const parts = []
for (let i = 0; i < v1.components.length; i++) {
if (v1.components[i] === 0) {
if (v1.components[i] === 0 && i < v1.components.length - 1) {
parts.push(0)
} else if (v1.components[i] > 0) {
} else {
parts.push(v1.components[i] + 1)
break
}
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/semver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ Deno.test("semver", async test => {
assert(l.satisfies(new SemVer("0.0.0.1")))
assertFalse(l.satisfies(new SemVer("0.0.0.2")))

// This one is weird, but it should mean "<1"
const m = new semver.Range("^0")
assert(m.satisfies(new SemVer("0.0.0")))
assert(m.satisfies(new SemVer("0.0.1")))
assert(m.satisfies(new SemVer("0.1.0")))
assert(m.satisfies(new SemVer("0.9.1")))
assertFalse(m.satisfies(new SemVer("1.0.0")))

assertThrows(() => new semver.Range("1"))
assertThrows(() => new semver.Range("1.2"))
assertThrows(() => new semver.Range("1.2.3"))
Expand Down

0 comments on commit 61da0e3

Please sign in to comment.