chore: abort if match strings are empty

This commit is contained in:
secustor
2022-07-14 16:51:05 +02:00
parent 58b6173019
commit bf41a92f43
2 changed files with 19 additions and 0 deletions
+13
View File
@@ -323,6 +323,19 @@ describe('modules/manager/regex/index', () => {
expect(res).toBeNull();
});
it('return with recursive strategy if matchStrings is empty', async () => {
const config: CustomExtractConfig = {
matchStrings: [],
matchStringsStrategy: 'recursive',
};
const res = await extractPackageFile(
exampleJsonContent,
'example.json',
config
);
expect(res).toBeNull();
});
it('extracts with recursive strategy and single match', async () => {
const config: CustomExtractConfig = {
matchStrings: [
+6
View File
@@ -61,6 +61,11 @@ export function handleRecursive(
const regexes = config.matchStrings.map((matchString) =>
regEx(matchString, 'g')
);
if (!regexes.length) {
return [];
}
// abort if we have no matchString anymore
if (!regexes[index]) {
const result = createDependency(
@@ -82,5 +87,6 @@ export function handleRecursive(
mergeGroups(combinedGroups, match.groups ?? {})
);
})
.filter(is.truthy)
.filter(isValidDependency);
}