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 48896e8 commit 9dbe9ad
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var forEach = require('for-each');
var inspect = require('object-inspect');
var isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
var toLowerCase = callBound('String.prototype.toLowerCase');
var $test = callBound('RegExp.prototype.test');
var $exec = callBound('RegExp.prototype.exec');
var objectToString = callBound('Object.prototype.toString');

module.exports = Test;
Expand Down Expand Up @@ -553,7 +553,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) {
var passed = caught;

if (isRegExp(expected)) {
passed = $test(expected, caught && caught.error);
passed = $exec(expected, caught && caught.error) !== null;
expected = String(expected);
}

Expand Down Expand Up @@ -610,7 +610,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 @@ -643,7 +643,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 9dbe9ad

Please sign in to comment.