Skip to content

Commit

Permalink
fix(pep440): fix exception matching two ranges (#28827)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <[email protected]>
  • Loading branch information
rarkins and viceice committed May 4, 2024
1 parent dc301be commit cec37bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/modules/versioning/pep440/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ describe('modules/versioning/pep440/index', () => {
expect(pep440.equals(a, b)).toBe(expected);
});

it.each`
a | b | expected
${'1.0'} | ${'>=1.0.0'} | ${true}
${'>=3.8'} | ${'>=3.9'} | ${false}
`('matches($a, $b) === $expected', ({ a, b, expected }) => {
expect(pep440.matches(a, b)).toBe(expected);
});

it.each`
version | isSingle
${'1.2.3'} | ${true}
Expand Down
6 changes: 5 additions & 1 deletion lib/modules/versioning/pep440/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const supportedRangeStrategies: RangeStrategy[] = [

const {
compare: sortVersions,
satisfies: matches,
satisfies,
valid,
validRange,
explain,
Expand Down Expand Up @@ -74,6 +74,10 @@ export { isVersion, matches };
const equals = (version1: string, version2: string): boolean =>
isVersion(version1) && isVersion(version2) && eq(version1, version2);

function matches(version: string, range: string): boolean {
return isVersion(version) && isValid(range) && satisfies(version, range);
}

export const api: VersioningApi = {
equals,
getMajor,
Expand Down

0 comments on commit cec37bb

Please sign in to comment.