Skip to content

Commit

Permalink
fix(manager/terraform): prevent endless loop in case of multiple cons…
Browse files Browse the repository at this point in the history
…traint elements (#26049)
  • Loading branch information
secustor authored Dec 1, 2023
1 parent 245f77b commit c11037b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 13 additions & 0 deletions lib/modules/manager/terraform/lockfile/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1104,5 +1104,18 @@ describe('modules/manager/terraform/lockfile/index', () => {
),
).toBe('5.26.0');
});

it('update constraint with multiple elements', () => {
expect(
getNewConstraint(
{
currentValue: '2.41.0',
newValue: '2.46.0',
newVersion: '2.46.0',
},
'>= 2.36.0, 2.41.0',
),
).toBe('>= 2.36.0, 2.46.0');
});
});
});
10 changes: 5 additions & 5 deletions lib/modules/manager/terraform/lockfile/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import is from '@sindresorhus/is';
import { logger } from '../../../../logger';
import * as p from '../../../../util/promises';
import { escapeRegExp, regEx } from '../../../../util/regex';
import { GetPkgReleasesConfig, getPkgReleases } from '../../../datasource';
import { TerraformProviderDatasource } from '../../../datasource/terraform-provider';
import { get as getVersioning } from '../../../versioning';
Expand Down Expand Up @@ -88,12 +89,11 @@ export function getNewConstraint(
logger.debug(
`Updating constraint "${oldConstraint}" to replace "${currentValue}" with "${newValue}" for "${packageName}"`,
);
let newConstraint = oldConstraint.replace(currentValue, newValue);
//remove surplus .0 version
while (newConstraint.split('.').length - 1 > 2) {
newConstraint = newConstraint.replace(RegExp('\\.0$'), '');
}
return newConstraint;
return oldConstraint.replace(
regEx(`${escapeRegExp(currentValue)}(\\.0)*`),
newValue,
);
}

if (
Expand Down

0 comments on commit c11037b

Please sign in to comment.