Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/transport/binary/protocol28/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function serializeDocument (document, isMap) {
function serializeValue (value) {
var type = typeof value;
if (type === 'string') {
return '"' + value.replace(/\\/, "\\\\").replace(/"/g, '\\"') + '"';
return '"' + value.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"';
}
else if (type === 'number') {
return ~value.toString().indexOf('.') ? value + 'f' : value;
Expand Down
27 changes: 27 additions & 0 deletions test/bugs/328-wrong-backslash-quoting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe("Bug #328: wrong serialization of fields with multiple backslash characters", function () {
before(function () {
return CREATE_TEST_DB(this, 'testdb_bug_328')
.bind(this)
.then(function () {
return this.db.class.create('TestSerializeBackslash');
});
});
after(function () {
return DELETE_TEST_DB('testdb_bug_328');
});

it('should insert a document with correct quotes for backslashes', function () {
return this.db
.insert()
.into('TestSerializeBackslash')
.set({
foo: 'kratke, , nadherne, proste bozi, chjo som sa ostrihal :\\\\',
bar: '>'
})
.one()
.then(function (res) {
res.foo.should.equal('kratke, , nadherne, proste bozi, chjo som sa ostrihal :\\\\');
});
});

});