Skip to content

Commit

Permalink
fix(versioning/hashicorp): check valid before matches (#19742)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jan 9, 2023
1 parent 1ab049f commit bf38439
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/modules/versioning/hashicorp/index.ts
@@ -1,3 +1,4 @@
import { logger } from '../../../logger';
import type { RangeStrategy } from '../../../types/versioning';
import { api as npm } from '../npm';
import type { NewValueConfig, VersioningApi } from '../types';
Expand Down Expand Up @@ -25,14 +26,15 @@ export function isValid(input: string): boolean {
try {
return npm.isValid(hashicorp2npm(input));
} catch (err) {
logger.debug({ value: input }, 'Unsupported hashicorp versioning value');
return false;
}
}
return false;
}

function matches(version: string, range: string): boolean {
return npm.matches(version, hashicorp2npm(range));
return isValid(range) && npm.matches(version, hashicorp2npm(range));
}

function getSatisfyingVersion(
Expand Down
1 change: 1 addition & 0 deletions lib/util/package-rules/current-version.ts
Expand Up @@ -39,6 +39,7 @@ export class CurrentVersionMatcher extends Matcher {
isUnconstrainedValue ||
!!(
currentValue &&
version.isValid(currentValue) &&
version.matches(matchCurrentVersionStr, currentValue)
)
);
Expand Down
1 change: 1 addition & 0 deletions lib/util/package-rules/index.spec.ts
Expand Up @@ -727,6 +727,7 @@ describe('util/package-rules/index', () => {
x: 1,
},
],
versioning: 'npm',
};
const res1 = applyPackageRules({
...config,
Expand Down

0 comments on commit bf38439

Please sign in to comment.