Skip to content

Commit

Permalink
fix(versioning/composer): handle abnormal subset ranges (#22319)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed May 19, 2023
1 parent 3164401 commit 735129b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/modules/versioning/composer/index.spec.ts
Expand Up @@ -69,6 +69,8 @@ describe('modules/versioning/composer/index', () => {
${'~1.0 | ~2.0'} | ${true}
${'~1.0||~2.0'} | ${true}
${'~1.0 || ~2.0'} | ${true}
${'<8.0-DEV'} | ${true}
${'<8-DEV'} | ${true}
`('isValid("$version") === $expected', ({ version, expected }) => {
const res = !!semver.isValid(version);
expect(res).toBe(expected);
Expand Down Expand Up @@ -134,6 +136,8 @@ describe('modules/versioning/composer/index', () => {
${'^1.0.0'} | ${'^0.9.0'} | ${false}
${'^1.1.0 || ^2.0.0'} | ${'^1.0.0 || ^2.0.0'} | ${true}
${'^1.0.0 || ^2.0.0'} | ${'^1.1.0 || ^2.0.0'} | ${false}
${'^7.0.0'} | ${'<8.0-DEV'} | ${true}
${'^7.0.0'} | ${'less than 8'} | ${false}
`('subset("$a", "$b") === $expected', ({ a, b, expected }) => {
expect(semver.subset!(a, b)).toBe(expected);
});
Expand Down
12 changes: 11 additions & 1 deletion lib/modules/versioning/composer/index.ts
Expand Up @@ -91,6 +91,11 @@ function composer2npm(input: string): string {
'>=$1 <1'
);

// add extra digits to <8-DEV and <8.0-DEV
output = output
.replace(regEx(/^(<\d+(\.\d+)?)$/g), '$1.0')
.replace(regEx(/^(<\d+(\.\d+)?)$/g), '$1.0');

return output + stability;
})
.map((part) => part.replace(/([a-z])([0-9])/gi, '$1.$2'))
Expand Down Expand Up @@ -171,7 +176,12 @@ function minSatisfyingVersion(
}

function subset(subRange: string, superRange: string): boolean | undefined {
return npm.subset!(composer2npm(subRange), composer2npm(superRange));
try {
return npm.subset!(composer2npm(subRange), composer2npm(superRange));
} catch (err) {
logger.trace({ err }, 'composer.subset error');
return false;
}
}

function getNewValue({
Expand Down

0 comments on commit 735129b

Please sign in to comment.