Test for good behavior with newlines

pull/2/head
Louis Chatriot 11 years ago
parent b4ae736d4d
commit 9f32b1eb72
  1. 31
      test/model.test.js

@ -4,6 +4,8 @@ var model = require('../lib/model')
, _ = require('underscore') , _ = require('underscore')
, async = require('async') , async = require('async')
, util = require('util') , util = require('util')
, Datastore = require('../lib/datastore')
, fs = require('fs')
; ;
@ -126,6 +128,35 @@ describe('Model', function () {
b = model.serialize(e2); b = model.serialize(e2);
}); });
it('Can serialize string fields with a new line without breaking the DB', function (done) {
var db1, db2
, badString = "world\r\nearth\nother\rline"
;
if (fs.existsSync('workspace/test1.db')) { fs.unlinkSync('workspace/test1.db'); }
fs.existsSync('workspace/test1.db').should.equal(false);
db1 = new Datastore({ filename: 'workspace/test1.db' });
db1.loadDatabase(function (err) {
assert.isNull(err);
db1.insert({ hello: badString }, function (err) {
assert.isNull(err);
db2 = new Datastore({ filename: 'workspace/test1.db' });
db2.loadDatabase(function (err) {
assert.isNull(err);
db2.find({}, function (err, docs) {
assert.isNull(err);
docs.length.should.equal(1);
docs[0].hello.should.equal(badString);
done();
});
});
});
});
});
}); // ==== End of 'Serialization, deserialization' ==== // }); // ==== End of 'Serialization, deserialization' ==== //

Loading…
Cancel
Save