From b657083edd1ae0e25717034382ced2855cb258ba Mon Sep 17 00:00:00 2001 From: Luigi Dell'Aquila Date: Fri, 12 Jun 2015 16:30:33 +0200 Subject: [PATCH 1/3] fixed serializasion issue when a field value contains multiple backslash characters --- lib/transport/binary/protocol28/serializer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/transport/binary/protocol28/serializer.js b/lib/transport/binary/protocol28/serializer.js index b2e6933..5d9b993 100644 --- a/lib/transport/binary/protocol28/serializer.js +++ b/lib/transport/binary/protocol28/serializer.js @@ -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; From ecb6205b9e1e19d7359b70992a118631ac4185f6 Mon Sep 17 00:00:00 2001 From: Luigi Dell'Aquila Date: Fri, 12 Jun 2015 17:54:24 +0200 Subject: [PATCH 2/3] providing test case for #328 --- test/bugs/328-wrong-backslash-quoting.js | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/bugs/328-wrong-backslash-quoting.js diff --git a/test/bugs/328-wrong-backslash-quoting.js b/test/bugs/328-wrong-backslash-quoting.js new file mode 100644 index 0000000..0c02bff --- /dev/null +++ b/test/bugs/328-wrong-backslash-quoting.js @@ -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 with correct quotes', 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 :\\\\'); + }); + }); + +}); From 119fd51de4b8c7fb3ee3d715b8d5717619fd8177 Mon Sep 17 00:00:00 2001 From: Luigi Dell'Aquila Date: Fri, 12 Jun 2015 17:56:06 +0200 Subject: [PATCH 3/3] just typos on a test case --- test/bugs/328-wrong-backslash-quoting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bugs/328-wrong-backslash-quoting.js b/test/bugs/328-wrong-backslash-quoting.js index 0c02bff..3cca293 100644 --- a/test/bugs/328-wrong-backslash-quoting.js +++ b/test/bugs/328-wrong-backslash-quoting.js @@ -10,7 +10,7 @@ describe("Bug #328: wrong serialization of fields with multiple backslash charac return DELETE_TEST_DB('testdb_bug_328'); }); - it('should insert a document with with correct quotes', function () { + it('should insert a document with correct quotes for backslashes', function () { return this.db .insert() .into('TestSerializeBackslash')