mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 22:21:20 +02:00
Add maximum number of recursivity for normalization
This commit is contained in:
@@ -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,17 +85,28 @@ 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
|
||||||
// Iterate over its children
|
|
||||||
transform = _normalizeChildrenWith(transform, schema, node)
|
|
||||||
|
|
||||||
// Refresh the node reference, and normalize it
|
// Auxiliary function, called recursively, with a maximum calls safety net.
|
||||||
node = _refreshNode(transform, node)
|
function _recur() {
|
||||||
if (node) {
|
recursiveCount++
|
||||||
transform = _normalizeNodeWith(transform, schema, node)
|
if (recursiveCount > MAX_CALLS) {
|
||||||
|
warning('Unexpected number of successive normalizations. Aborting.')
|
||||||
|
return transform
|
||||||
|
}
|
||||||
|
// Iterate over its children
|
||||||
|
transform = _normalizeChildrenWith(transform, schema, node)
|
||||||
|
|
||||||
|
// Refresh the node reference, and normalize it
|
||||||
|
node = _refreshNode(transform, node)
|
||||||
|
if (node) {
|
||||||
|
transform = _normalizeNodeWith(transform, schema, node)
|
||||||
|
}
|
||||||
|
|
||||||
|
return transform
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform
|
return _recur(transform, schema, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user