in apps/mountebank-mock/mountebank-source/src/models/predicates.js [325:347]
function matches (predicate, request, encoding, logger) {
// We want to avoid the lowerCase transform on values so we don't accidentally butcher
// a regular expression with upper case metacharacters like \W and \S
// However, we need to maintain the case transform for keys like http header names (issue #169)
// eslint-disable-next-line no-unneeded-ternary
const caseSensitive = predicate.caseSensitive ? true : false, // convert to boolean even if undefined
clone = helpers.merge(predicate, { caseSensitive: true, keyCaseSensitive: caseSensitive }),
noexcept = helpers.merge(clone, { except: '' }),
expected = normalize(predicate.matches, noexcept, { encoding: encoding }, logger),
actual = normalize(request, clone, { encoding: encoding, withSelectors: true }, logger),
options = caseSensitive ? '' : 'i';
if (encoding === 'base64') {
throw errors.ValidationError('the matches predicate is not allowed in binary mode');
}
return predicateSatisfied(expected, actual, clone, (a, b) => {
if (!safeRegex(a)) {
logger.warn(`If mountebank becomes unresponsive, it is because of this unsafe regular expression: ${a}`);
}
return new RegExp(a, options).test(b);
});
}