Skip to content

Commit 56e6e56

Browse files
committed
fix: The editor can be crashed by passing in undefined into the setValue method
1 parent c46c0c3 commit 56e6e56

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Diff for: src/document.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var Document = function(textOrLines) {
4646
this.setValue = function(text) {
4747
var len = this.getLength() - 1;
4848
this.remove(new Range(0, 0, len, this.getLine(len).length));
49-
this.insert({row: 0, column: 0}, text);
49+
this.insert({row: 0, column: 0}, text || "");
5050
};
5151

5252
/**

Diff for: src/edit_session_test.js

+15
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,21 @@ module.exports = {
498498
assert.equal(session.$foldData.length, 0);
499499
},
500500

501+
"test setting undefined value": function() {
502+
var session = createFoldTestSession();
503+
var editor = new Editor(new MockRenderer(), session);
504+
editor.setOption("mode", new JavaScriptMode());
505+
506+
editor.setValue("test");
507+
assert.equal(session.getValue(), "test");
508+
509+
editor.setValue(undefined);
510+
assert.equal(session.getValue(), "");
511+
512+
editor.setValue("test");
513+
assert.equal(session.getValue(), "test");
514+
},
515+
501516
"test foldOther": function() {
502517
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}");
503518
var editor = new Editor(new MockRenderer(), session);

0 commit comments

Comments
 (0)