From 9dbe9ad9163835edb302505dec26a8e21f20d893 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 8 Apr 2022 10:52:24 -0700 Subject: [PATCH] [Robustness] `test` observably looks up `exec` on the object --- lib/test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/test.js b/lib/test.js index e582b876..2e6c8a0b 100644 --- a/lib/test.js +++ b/lib/test.js @@ -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; @@ -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); } @@ -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) @@ -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)