Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(versioning/composer): handle abnormal subset ranges #22319

Merged
merged 1 commit into from May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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