Skip to content

Commit

Permalink
fix: The editor can be crashed by passing in undefined into the setVa…
Browse files Browse the repository at this point in the history
…lue method
  • Loading branch information
andrewnester committed Sep 21, 2022
1 parent c46c0c3 commit 56e6e56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var Document = function(textOrLines) {
this.setValue = function(text) {
var len = this.getLength() - 1;
this.remove(new Range(0, 0, len, this.getLine(len).length));
this.insert({row: 0, column: 0}, text);
this.insert({row: 0, column: 0}, text || "");
};

/**
Expand Down
15 changes: 15 additions & 0 deletions src/edit_session_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,21 @@ module.exports = {
assert.equal(session.$foldData.length, 0);
},

"test setting undefined value": function() {
var session = createFoldTestSession();
var editor = new Editor(new MockRenderer(), session);
editor.setOption("mode", new JavaScriptMode());

editor.setValue("test");
assert.equal(session.getValue(), "test");

editor.setValue(undefined);
assert.equal(session.getValue(), "");

editor.setValue("test");
assert.equal(session.getValue(), "test");
},

"test foldOther": function() {
var session = new EditSession("{\n\t1{\n\t\t\n\t\t1.1 {\n\t\t}\n\t}\n\t2 {\n\t\t2.1 {\n\t\t\t2.2 {\n\t\t\t}\n\t\t\t2.3 {\n\t\t\t}\n\t\t}\n\t}\n}\n\n{\n}");
var editor = new Editor(new MockRenderer(), session);
Expand Down

0 comments on commit 56e6e56

Please sign in to comment.