Repository navigation
Conversation
…mitives Date, RegExp, and boxed-primitive (String/Number/Boolean) instances were compared only by their internal value (valueOf/toString), so two such objects with differing own enumerable data properties were reported as deeply equal. This contradicts the documented rule that all own and inherited enumerable properties are considered (only Error is exempt) and diverges from node's util.isDeepStrictEqual. AND the type-specific value check with the existing objectEqual own-key comparison so extra own properties are taken into account while valueOf, -0/NaN, and the Error special-case semantics are preserved.
5690c87 to
61c4be2
Compare
|
Rebased on main. The only conflict was in |
|
since this is just an agent, im going to close this until a human shows that this is a problem in need of a fix. |
|
Hi, this is spokodev, I'm a real person here. Yes, I work with an AI agent, but I checked this one. I found it by checking the README rule against the code, not from a failing project. Where these objects do come up: path-to-regexp 1.x, which react-router 5 depends on, returns a RegExp with an enumerable |
|
if it comes up again we can revisit 👍 i.e. if there's demand for it |
Problem
deep-eqlignores own enumerable properties onDate,RegExp, and boxed-primitive (String/Number/Boolean) instances. Two such objects are reported deeply equal even when they carry differing own enumerable data properties.Same for
RegExp(const r = /x/; r.foo = ...) and boxednew Number(1)/new String(...)/new Boolean(...).This contradicts the documented contract in the README "Rules" section:
Only
Erroris documented as an exception. The control case is already correct (eql({foo:1}, {foo:2}) === false), which shows that only the special-cased types bypass the rule.Root cause
In
extensiveDeepEqualByType(), theString/Number/Boolean/Datebranch returns only thevalueOf()comparison, and theRegExpbranch returns only thetoString()comparison. Bothreturnbefore theobjectEqual()default branch, so own enumerable properties are never compared.Fix
AND the type-specific value check with the existing
objectEqual()own-enumerable-key comparison for those branches.objectEqual()already returnstruewhen both sides have zero own enumerable keys, so plain instances are unaffected.valueOf/-0/NaNsemantics and the documentedErrorspecial-case are untouched.Verification
Red -> green: 5 new tests (one per affected type) assert that instances with differing own enumerable properties are not equal. They fail before the fix and pass after.
Each new case was cross-checked against
node:util.isDeepStrictEqualas an oracle, including the cases that must stay equal (same prop value, no extra props,new Number(NaN),new Date(NaN)) and theErrorspecial-case (extra own props still ignored, as documented).After rebasing on main: lint clean,
test:node185 passing,test:browser(Chrome) 183 passed and 2 skipped. With main'sindex.js, exactly the 5 new tests fail. #118 addedcase 'BigInt':to the same branch, so a boxed BigInt with differing own enumerable properties is now not equal either, asutil.isDeepStrictEqualreports.