Skip to content

Commit

Permalink
Fix deepEqual for null values (josdejong#600)
Browse files Browse the repository at this point in the history
When doing a `.update` on an editor that was showing an object and
replacing it with `null`, a runtime exception occurs. This is because
the `deepEqual` check doesn't account for the fact that `typeof null ===
'object'`, so it tries to access properties of a null value.
  • Loading branch information
jpage-godaddy authored and josdejong committed Nov 13, 2018
1 parent bd8bac0 commit 3065dad
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/js/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Node.prototype.getName = function () {

/**
* Find child node by serializable path
* @param {Array<String>} path
* @param {Array<String>} path
*/
Node.prototype.findNodeByPath = function (path) {
if (!path) {
Expand Down Expand Up @@ -186,7 +186,7 @@ Node.prototype.findNodeByInternalPath = function (internalPath) {

/**
* @typedef {{value: String|Object|Number|Boolean, path: Array.<String|Number>}} SerializableNode
*
*
* Returns serializable representation for the node
* @return {SerializableNode}
*/
Expand Down Expand Up @@ -1469,7 +1469,7 @@ Node.prototype.deepEqual = function (json) {
}
}
else if (this.type === 'object') {
if (typeof json !== 'object') {
if (typeof json !== 'object' || !json) {
return false;
}

Expand Down Expand Up @@ -2516,7 +2516,7 @@ Node.prototype._updateSchema = function () {
//Locating the schema of the node and checking for any enum type
if(this.editor && this.editor.options) {
// find the part of the json schema matching this nodes path
this.schema = this.editor.options.schema
this.schema = this.editor.options.schema
? Node._findSchema(this.editor.options.schema, this.getPath())
: null;
if (this.schema) {
Expand Down Expand Up @@ -2957,7 +2957,7 @@ Node.prototype._onEvent = function (event) {
};
// For leaf values, include value
if (!this._hasChilds() &&element === this.dom.value) {
info.value = this.getValue();
info.value = this.getValue();
}
this.editor.options.onEvent(info, event);
}
Expand Down

0 comments on commit 3065dad

Please sign in to comment.