Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/api/assert.md10
-rw-r--r--lib/internal/util/comparisons.js4
-rw-r--r--test/parallel/test-assert-deep.js4
3 files changed, 15 insertions, 3 deletions
diff --git a/doc/api/assert.md b/doc/api/assert.md
index a22a6082c3a..c7e679ef814 100644
--- a/doc/api/assert.md
+++ b/doc/api/assert.md
@@ -465,6 +465,9 @@ An alias of [`assert.ok()`][].
<!-- YAML
added: v0.1.21
changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/41020
+ description: Regular expressions lastIndex property is now compared as well.
- version:
- v16.0.0
- v14.18.0
@@ -539,6 +542,8 @@ are also recursively evaluated by the following rules.
objects.
* [`Symbol`][] properties are not compared.
* [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values.
+* [`RegExp`][] lastIndex, flags and source are always compared, even if these
+ are not enumerable properties.
The following example does not throw an [`AssertionError`][] because the
primitives are considered equal by the [Abstract Equality Comparison][]
@@ -642,6 +647,9 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
<!-- YAML
added: v1.2.0
changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/41020
+ description: Regular expressions lastIndex property is now compared as well.
- version: v9.0.0
pr-url: https://github.com/nodejs/node/pull/15169
description: Enumerable symbol properties are now compared.
@@ -697,6 +705,8 @@ are recursively evaluated also by the following rules.
reference.
* [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values. See
below for further details.
+* [`RegExp`][] lastIndex, flags and source are always compared, even if these
+ are not enumerable properties.
```mjs
import assert from 'assert/strict';
diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js
index 95515fb78ac..c126bd6346d 100644
--- a/lib/internal/util/comparisons.js
+++ b/lib/internal/util/comparisons.js
@@ -63,7 +63,9 @@ const kIsMap = 3;
// Check if they have the same source and flags
function areSimilarRegExps(a, b) {
- return a.source === b.source && a.flags === b.flags;
+ return a.source === b.source &&
+ a.flags === b.flags &&
+ a.lastIndex === b.lastIndex;
}
function areSimilarFloatArrays(a, b) {
diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js
index bdc634fb5f6..22e01afff15 100644
--- a/test/parallel/test-assert-deep.js
+++ b/test/parallel/test-assert-deep.js
@@ -712,7 +712,7 @@ assertNotDeepOrStrict(/a/igm, /a/im);
{
const re1 = /a/g;
re1.lastIndex = 3;
- assert.deepEqual(re1, /a/g);
+ assert.notDeepEqual(re1, /a/g);
}
assert.deepEqual(4, '4');
@@ -852,7 +852,7 @@ assert.throws(
{
const re1 = /a/;
re1.lastIndex = 3;
- assert.deepStrictEqual(re1, /a/);
+ assert.notDeepStrictEqual(re1, /a/);
}
assert.throws(