summaryrefslogtreecommitdiff
path: root/src/node/db
diff options
context:
space:
mode:
authorXavid <xavid@mit.edu>2015-06-30 04:47:55 -0400
committerXavid <xavid@mit.edu>2015-06-30 04:47:55 -0400
commitad137fa4c876f9d7dc2d8113d8bcef9b9425ce0c (patch)
tree74f82ba67999d1dd718802fbe1dbdccb302d88b6 /src/node/db
parentd803ac128ecae61402d98bdf14f547c5fd52a1c4 (diff)
downloadetherpad-lite-ad137fa4c876f9d7dc2d8113d8bcef9b9425ce0c.zip
Restore newline-adding to setText() if passed string does not end in '\n'.
Add a test for the ending-in-'\n' case and update tests for the other case.
Diffstat (limited to 'src/node/db')
-rw-r--r--src/node/db/Pad.js9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js
index 8978d253..eb6a3ed1 100644
--- a/src/node/db/Pad.js
+++ b/src/node/db/Pad.js
@@ -290,7 +290,14 @@ Pad.prototype.setText = function setText(newText) {
var oldText = this.text();
//create the changeset
- var changeset = Changeset.makeSplice(oldText, 0, oldText.length, newText);
+ // We want to ensure the pad still ends with a \n, but otherwise keep
+ // getText() and setText() consistent.
+ var changeset;
+ if (newText[newText.length - 1] == '\n') {
+ changeset = Changeset.makeSplice(oldText, 0, oldText.length, newText);
+ } else {
+ changeset = Changeset.makeSplice(oldText, 0, oldText.length-1, newText);
+ }
//append the changeset
this.appendRevision(changeset);