diff --git a/src/utils/versioning/version-range.ts b/src/utils/versioning/version-range.ts index 45b9b8e..c82aa2e 100644 --- a/src/utils/versioning/version-range.ts +++ b/src/utils/versioning/version-range.ts @@ -85,7 +85,7 @@ function mixedToSemver(range: string): string { /** * Regular expression for matching interval expressions in version range strings. */ -const INTERVAL_REGEX = /(?\[|\()\s*(?[^,\s]+)?\s*,\s*(?[^,\s\])]+)?\s*(?\]|\))/; +const INTERVAL_REGEX = /(?\[|\()\s*(?[^,\s]+)?\s*(?,)?\s*(?[^,\s\])]+)?\s*(?\]|\))/; /** * Converts an interval expression into a semver-compatible range expression. @@ -102,6 +102,7 @@ function intervalToSemver(range: string): string { const fromOperator = match.groups.from_bracket === "[" ? ">=" : ">"; const from = match.groups.from; + const separator = match.groups.separator; const toOperator = match.groups.to_bracket === "]" ? "<=" : "<"; const to = match.groups.to; if (!from && !to) { @@ -112,6 +113,10 @@ function intervalToSemver(range: string): string { return `${toOperator}${to}`; } + if (!separator) { + return from; + } + if (!to) { return `${fromOperator}${from}`; } diff --git a/tests/unit/utils/versioning/version-range.spec.ts b/tests/unit/utils/versioning/version-range.spec.ts index a875a07..1db699b 100644 --- a/tests/unit/utils/versioning/version-range.spec.ts +++ b/tests/unit/utils/versioning/version-range.spec.ts @@ -69,6 +69,48 @@ describe("parseVersionRange", () => { expect(versionRange.includes("2.0.1")).toBe(false); }); + test("parses an interval notation string with single version correctly", () => { + const versionRange = parseVersionRange("[1.2.3]"); + + expect(versionRange).toBeDefined(); + expect(versionRange.toString()).toBe("[1.2.3]"); + + expect(versionRange.includes("1.2.3")).toBe(true); + expect(versionRange.includes("1.2.4")).toBe(false); + expect(versionRange.includes("2.0.0")).toBe(false); + expect(versionRange.includes("1.0.0")).toBe(false); + expect(versionRange.includes("1.2.2")).toBe(false); + expect(versionRange.includes("2.0.1")).toBe(false); + }); + + test("parses an interval notation string with single version open end correctly", () => { + const versionRange = parseVersionRange("[1.2.3,)"); + + expect(versionRange).toBeDefined(); + expect(versionRange.toString()).toBe("[1.2.3,)"); + + expect(versionRange.includes("1.2.3")).toBe(true); + expect(versionRange.includes("1.2.4")).toBe(true); + expect(versionRange.includes("2.0.0")).toBe(true); + expect(versionRange.includes("2.0.1")).toBe(true); + expect(versionRange.includes("1.0.0")).toBe(false); + expect(versionRange.includes("1.2.2")).toBe(false); + }); + + test("parses an interval notation string with single version closed end as typo for open end", () => { + const versionRange = parseVersionRange("[1.2.3,]"); + + expect(versionRange).toBeDefined(); + expect(versionRange.toString()).toBe("[1.2.3,]"); + + expect(versionRange.includes("1.2.3")).toBe(true); + expect(versionRange.includes("1.2.4")).toBe(true); + expect(versionRange.includes("2.0.0")).toBe(true); + expect(versionRange.includes("2.0.1")).toBe(true); + expect(versionRange.includes("1.0.0")).toBe(false); + expect(versionRange.includes("1.2.2")).toBe(false); + }); + test("parses an interval notation string with X-ranges correctly", () => { const versionRange = parseVersionRange("[1.2.x,2.0.X)");