Skip to content

Commit

Permalink
Merge pull request #4930 from andrewnester/fix-4784
Browse files Browse the repository at this point in the history
fix: The editor can be crashed by passing in undefined into the setValue method
  • Loading branch information
nightwing committed Sep 22, 2022
2 parents 0366ba0 + 56e6e56 commit 5304519
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
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
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 5304519

Please sign in to comment.