Skip to content

Commit

Permalink
added try catch block to get node to protect from malformed IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
vakata committed Jan 4, 2014
1 parent 69446c2 commit 9dc1f35
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 51 deletions.
34 changes: 18 additions & 16 deletions dist/jstree.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,23 +764,25 @@
obj = obj.id;
}
var dom;
if(this._model.data[obj]) {
obj = this._model.data[obj];
}
else if(((dom = $(obj, this.element)).length || (dom = $('#' + obj, this.element)).length) && this._model.data[dom.closest('li').attr('id')]) {
obj = this._model.data[dom.closest('li').attr('id')];
}
else if((dom = $(obj, this.element)).length && dom.hasClass('jstree')) {
obj = this._model.data['#'];
}
else {
return false;
}
try {
if(this._model.data[obj]) {
obj = this._model.data[obj];
}
else if(((dom = $(obj, this.element)).length || (dom = $('#' + obj, this.element)).length) && this._model.data[dom.closest('li').attr('id')]) {
obj = this._model.data[dom.closest('li').attr('id')];
}
else if((dom = $(obj, this.element)).length && dom.hasClass('jstree')) {
obj = this._model.data['#'];
}
else {
return false;
}

if(as_dom) {
obj = obj.id === '#' ? this.element : $(document.getElementById(obj.id));
}
return obj;
if(as_dom) {
obj = obj.id === '#' ? this.element : $(document.getElementById(obj.id));
}
return obj;
} catch (ex) { return false; }
},
/**
* get the next visible node that is below the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
Expand Down
2 changes: 1 addition & 1 deletion dist/jstree.min.js

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions docs/assets/dist/jstree.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,23 +764,25 @@
obj = obj.id;
}
var dom;
if(this._model.data[obj]) {
obj = this._model.data[obj];
}
else if(((dom = $(obj, this.element)).length || (dom = $('#' + obj, this.element)).length) && this._model.data[dom.closest('li').attr('id')]) {
obj = this._model.data[dom.closest('li').attr('id')];
}
else if((dom = $(obj, this.element)).length && dom.hasClass('jstree')) {
obj = this._model.data['#'];
}
else {
return false;
}
try {
if(this._model.data[obj]) {
obj = this._model.data[obj];
}
else if(((dom = $(obj, this.element)).length || (dom = $('#' + obj, this.element)).length) && this._model.data[dom.closest('li').attr('id')]) {
obj = this._model.data[dom.closest('li').attr('id')];
}
else if((dom = $(obj, this.element)).length && dom.hasClass('jstree')) {
obj = this._model.data['#'];
}
else {
return false;
}

if(as_dom) {
obj = obj.id === '#' ? this.element : $(document.getElementById(obj.id));
}
return obj;
if(as_dom) {
obj = obj.id === '#' ? this.element : $(document.getElementById(obj.id));
}
return obj;
} catch (ex) { return false; }
},
/**
* get the next visible node that is below the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/dist/jstree.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/jstree.json
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@
},
"isPrivate": false,
"ignore": false,
"code": "get_node : function (obj, as_dom) {\n\t\t\tif(obj && obj.id) {\n\t\t\t\tobj = obj.id;\n\t\t\t}\n\t\t\tvar dom;\n\t\t\tif(this._model.data[obj]) {\n\t\t\t\tobj = this._model.data[obj];\n\t\t\t}\n\t\t\telse if(((dom = $(obj, this.element)).length || (dom = $('#' + obj, this.element)).length) && this._model.data[dom.closest('li').attr('id')]) {\n\t\t\t\tobj = this._model.data[dom.closest('li').attr('id')];\n\t\t\t}\n\t\t\telse if((dom = $(obj, this.element)).length && dom.hasClass('jstree')) {\n\t\t\t\tobj = this._model.data['#'];\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif(as_dom) {\n\t\t\t\tobj = obj.id === '#' ? this.element : $(document.getElementById(obj.id));\n\t\t\t}\n\t\t\treturn obj;\n\t\t},"
"code": "get_node : function (obj, as_dom) {\n\t\t\tif(obj && obj.id) {\n\t\t\t\tobj = obj.id;\n\t\t\t}\n\t\t\tvar dom;\n\t\t\ttry {\n\t\t\t\tif(this._model.data[obj]) {\n\t\t\t\t\tobj = this._model.data[obj];\n\t\t\t\t}\n\t\t\t\telse if(((dom = $(obj, this.element)).length || (dom = $('#' + obj, this.element)).length) && this._model.data[dom.closest('li').attr('id')]) {\n\t\t\t\t\tobj = this._model.data[dom.closest('li').attr('id')];\n\t\t\t\t}\n\t\t\t\telse if((dom = $(obj, this.element)).length && dom.hasClass('jstree')) {\n\t\t\t\t\tobj = this._model.data['#'];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif(as_dom) {\n\t\t\t\t\tobj = obj.id === '#' ? this.element : $(document.getElementById(obj.id));\n\t\t\t\t}\n\t\t\t\treturn obj;\n\t\t\t} catch (ex) { return false; }\n\t\t},"
},
{
"tags": [
Expand Down
34 changes: 18 additions & 16 deletions src/jstree.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,23 +764,25 @@
obj = obj.id;
}
var dom;
if(this._model.data[obj]) {
obj = this._model.data[obj];
}
else if(((dom = $(obj, this.element)).length || (dom = $('#' + obj, this.element)).length) && this._model.data[dom.closest('li').attr('id')]) {
obj = this._model.data[dom.closest('li').attr('id')];
}
else if((dom = $(obj, this.element)).length && dom.hasClass('jstree')) {
obj = this._model.data['#'];
}
else {
return false;
}
try {
if(this._model.data[obj]) {
obj = this._model.data[obj];
}
else if(((dom = $(obj, this.element)).length || (dom = $('#' + obj, this.element)).length) && this._model.data[dom.closest('li').attr('id')]) {
obj = this._model.data[dom.closest('li').attr('id')];
}
else if((dom = $(obj, this.element)).length && dom.hasClass('jstree')) {
obj = this._model.data['#'];
}
else {
return false;
}

if(as_dom) {
obj = obj.id === '#' ? this.element : $(document.getElementById(obj.id));
}
return obj;
if(as_dom) {
obj = obj.id === '#' ? this.element : $(document.getElementById(obj.id));
}
return obj;
} catch (ex) { return false; }
},
/**
* get the next visible node that is below the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
Expand Down

0 comments on commit 9dc1f35

Please sign in to comment.