mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 23:16:26 +00:00
feat: validate user regex (#1766)
Validate that user-inputted regex for package patterns are valid RegExp(). Closes #1450
This commit is contained in:
parent
90d3a2d92d
commit
484ef0cbcd
3 changed files with 26 additions and 1 deletions
|
@ -158,6 +158,19 @@ async function validateConfig(config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
(key === 'packagePatterns' || key === 'excludePackagePatterns') &&
|
||||||
|
!(val && val.length === 1 && val[0] === '*')
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
RegExp(val);
|
||||||
|
} catch (e) {
|
||||||
|
errors.push({
|
||||||
|
depName: 'Configuration Error',
|
||||||
|
message: `Invalid regExp for ${key}: \`${val}\``,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (type === 'string') {
|
} else if (type === 'string') {
|
||||||
if (!isString(val)) {
|
if (!isString(val)) {
|
||||||
|
|
|
@ -18,6 +18,14 @@ Array [
|
||||||
"depName": "Configuration Error",
|
"depName": "Configuration Error",
|
||||||
"message": "Invalid timezone: Asia",
|
"message": "Invalid timezone: Asia",
|
||||||
},
|
},
|
||||||
|
Object {
|
||||||
|
"depName": "Configuration Error",
|
||||||
|
"message": "Configuration option \`packagePatterns\` should be a list (Array)",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"depName": "Configuration Error",
|
||||||
|
"message": "Invalid regExp for excludePackagePatterns: \`abc ([a-z]+) ([a-z]+))\`",
|
||||||
|
},
|
||||||
Object {
|
Object {
|
||||||
"depName": "Configuration Error",
|
"depName": "Configuration Error",
|
||||||
"message": "Configuration option \`labels\` should be a list (Array)",
|
"message": "Configuration option \`labels\` should be a list (Array)",
|
||||||
|
|
|
@ -7,6 +7,8 @@ describe('config/validation', () => {
|
||||||
foo: 1,
|
foo: 1,
|
||||||
schedule: ['after 5pm'],
|
schedule: ['after 5pm'],
|
||||||
timezone: 'Asia/Singapore',
|
timezone: 'Asia/Singapore',
|
||||||
|
packagePatterns: ['*'],
|
||||||
|
excludePackagePatterns: ['[a-z]'],
|
||||||
prBody: 'some-body',
|
prBody: 'some-body',
|
||||||
lockFileMaintenance: {
|
lockFileMaintenance: {
|
||||||
bar: 2,
|
bar: 2,
|
||||||
|
@ -25,6 +27,8 @@ describe('config/validation', () => {
|
||||||
enabled: 1,
|
enabled: 1,
|
||||||
schedule: ['every 15 mins every weekday'],
|
schedule: ['every 15 mins every weekday'],
|
||||||
timezone: 'Asia',
|
timezone: 'Asia',
|
||||||
|
packagePatterns: 'abc ([a-z]+) ([a-z]+))',
|
||||||
|
excludePackagePatterns: ['abc ([a-z]+) ([a-z]+))'],
|
||||||
labels: 5,
|
labels: 5,
|
||||||
semanticCommitType: 7,
|
semanticCommitType: 7,
|
||||||
lockFileMaintenance: false,
|
lockFileMaintenance: false,
|
||||||
|
@ -45,7 +49,7 @@ describe('config/validation', () => {
|
||||||
);
|
);
|
||||||
expect(warnings).toHaveLength(0);
|
expect(warnings).toHaveLength(0);
|
||||||
expect(errors).toMatchSnapshot();
|
expect(errors).toMatchSnapshot();
|
||||||
expect(errors).toHaveLength(11);
|
expect(errors).toHaveLength(13);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue