Skip to content

Commit

Permalink
[Robustness] test observably looks up exec on the object
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 8, 2022
1 parent bf34f60 commit fa84c85
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/test.js
Expand Up @@ -18,7 +18,7 @@ var every = require('array.prototype.every');
var isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
var toLowerCase = callBound('String.prototype.toLowerCase');
var isProto = callBound('Object.prototype.isPrototypeOf');
var $test = callBound('RegExp.prototype.test');
var $exec = callBound('RegExp.prototype.exec');
var objectToString = callBound('Object.prototype.toString');
var $split = callBound('String.prototype.split');
var $replace = callBound('String.prototype.replace');
Expand Down Expand Up @@ -654,7 +654,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) {
passed = expected.call({}, caught.error) === true;
}
} else if (isRegExp(expected)) {
passed = $test(expected, caught.error);
passed = $exec(expected, caught.error) !== null;
expected = inspect(expected);
} else if (expected && typeof expected === 'object') { // Handle validation objects.
var keys = objectKeys(expected);
Expand All @@ -665,7 +665,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) {
throw new TypeError('`throws` validation object must not be empty');
}
passed = every(keys, function (key) {
if (typeof caught.error[key] === 'string' && isRegExp(expected[key]) && $test(expected[key], caught.error[key])) {
if (typeof caught.error[key] === 'string' && isRegExp(expected[key]) && $exec(expected[key], caught.error[key]) !== null) {
return true;
}
if (key in caught.error && deepEqual(caught.error[key], expected[key], { strict: true })) {
Expand Down Expand Up @@ -725,7 +725,7 @@ Test.prototype.match = function match(string, regexp, msg, extra) {
extra: extra
});
} else {
var matches = $test(regexp, string);
var matches = $exec(regexp, string) !== null;
var message = defined(
msg,
'The input ' + (matches ? 'matched' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)
Expand Down Expand Up @@ -758,7 +758,7 @@ Test.prototype.doesNotMatch = function doesNotMatch(string, regexp, msg, extra)
extra: extra
});
} else {
var matches = $test(regexp, string);
var matches = $exec(regexp, string) !== null;
var message = defined(
msg,
'The input ' + (matches ? 'was expected to not match' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)
Expand Down

0 comments on commit fa84c85

Please sign in to comment.