1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-21 06:31:28 +02:00

Add maximum number of recursivity for normalization

This commit is contained in:
Soreine
2016-10-27 17:11:08 +02:00
parent eb9b97d79e
commit 4fa097ab0b

View File

@@ -1,6 +1,9 @@
import warning from '../utils/warning' import warning from '../utils/warning'
import { default as defaultSchema } from '../plugins/schema' import { default as defaultSchema } from '../plugins/schema'
// Maximum recursive calls for normalization
const MAX_CALLS = 50
/** /**
* Refresh a reference to a node that have been modified in a transform. * Refresh a reference to a node that have been modified in a transform.
* @param {Transform} transform * @param {Transform} transform
@@ -82,7 +85,15 @@ function _normalizeNodeWith(transform, schema, node) {
*/ */
export function normalizeNodeWith(transform, schema, node) { export function normalizeNodeWith(transform, schema, node) {
// console.log(`normalize node key=${node.key}`) let recursiveCount = 0
// Auxiliary function, called recursively, with a maximum calls safety net.
function _recur() {
recursiveCount++
if (recursiveCount > MAX_CALLS) {
warning('Unexpected number of successive normalizations. Aborting.')
return transform
}
// Iterate over its children // Iterate over its children
transform = _normalizeChildrenWith(transform, schema, node) transform = _normalizeChildrenWith(transform, schema, node)
@@ -95,6 +106,9 @@ export function normalizeNodeWith(transform, schema, node) {
return transform return transform
} }
return _recur(transform, schema, node)
}
/** /**
* Normalize a node its parents using a schema. * Normalize a node its parents using a schema.
* *