1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-24 16:02:55 +02:00

Fixed nested object comparison when the second value doesn't have that key (#4518)

This commit is contained in:
Andrew Herron
2021-09-14 17:32:47 +10:00
committed by GitHub
parent d528ad4008
commit 6ec399d4db
3 changed files with 27 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
'slate': patch
---
Fixed flaw in deep-equal algorithm when dealing with nested mark objects

View File

@@ -17,7 +17,7 @@ export const isDeepEqual = (
for (const key in node) {
const a = node[key]
const b = another[key]
if (isPlainObject(a)) {
if (isPlainObject(a) && isPlainObject(b)) {
if (!isDeepEqual(a, b)) return false
} else if (Array.isArray(a) && Array.isArray(b)) {
if (a.length !== b.length) return false

View File

@@ -0,0 +1,21 @@
import { isDeepEqual } from '../../../src/utils/deep-equal'
export const input = {
objectA: {
text: 'same text',
bold: true,
italic: { origin: 'inherited', value: true },
underline: { origin: 'inherited', value: false },
},
objectB: {
text: 'same text',
bold: true,
italic: { origin: 'inherited', value: true },
},
}
export const test = ({ objectA, objectB }) => {
return isDeepEqual(objectA, objectB)
}
export const output = false