From 03af7b56f26d0c651ebc0448315b98b1d67936c6 Mon Sep 17 00:00:00 2001 From: rhjyy Date: Tue, 5 Feb 2019 14:13:28 +0800 Subject: [PATCH 1/4] fix a problem about Multi-Byte character If the data contains Multi-Byte character,it may be cut by the tcp packets,then the join function's result will contain some unintelligible text,because it turns the object in the array into string before the concat action.So,we should replace it with the Buffer class's member function concat. --- lib/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index 186e962c9..a5098d073 100644 --- a/lib/server.js +++ b/lib/server.js @@ -217,7 +217,7 @@ Server.prototype._requestListener = function (req, res) { chunks.push(chunk); }); source.on('end', function () { - var xml = chunks.join(''); + var xml = Buffer.concat(chunks).toString(); var result; var error; self._processRequestXml(req, res, xml); From 6e447b489b34a840599f8397b6bd667c76e739b9 Mon Sep 17 00:00:00 2001 From: rhjyy Date: Thu, 7 Feb 2019 13:59:51 +0800 Subject: [PATCH 2/4] add a test of a problem about multi-byte character The fix of this problem is in the commit 03af7b5.If the data contains Multi-Byte character,it may be cut by the tcp packets,then the join function's result will contain some unintelligible text,because it turns the object in the array into string before the concat action. --- test/post-data-concat-test.js | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/post-data-concat-test.js diff --git a/test/post-data-concat-test.js b/test/post-data-concat-test.js new file mode 100644 index 000000000..7fea40a4d --- /dev/null +++ b/test/post-data-concat-test.js @@ -0,0 +1,52 @@ +'use strict'; + +var fs = require('fs'); +var soap = require('..'); +var assert = require('assert'); +var http = require('http'); + + +describe('post data concat test', function () { + it('should consider the situation about multi-byte character between two tcp packets', function (done) { + var check = function (a, b) { + if (a && b) { + assert(a === b); + done(); + } + }; + + var wsdl = 'test/wsdl/default_namespace.wsdl'; + var server = http.createServer(function (req, res) { }); + var xml = fs.readFileSync(wsdl, 'utf8'); + var service = { + MyService: { + MyServicePort: { + MyOperation: function (arg) { + console.log(arg); + check(arg, postdata); + return "0"; + } + } + } + }; + + server.listen(51515); + soap.listen(server, '/wsdl', service, xml); + + var postdata = ""; + for (var i = 0; i < 20000; i++) { + postdata += "测试"; + } + + soap.createClient(wsdl, { + endpoint: 'http://localhost:51515/wsdl' + }, function (error, client) { + assert(!error); + client.MyOperation(postdata, function (error, response) { + server.close(); + }); + }); + + }); +}); + From 4d4a86d3847529de8cfc279cbe71dec1f83568c7 Mon Sep 17 00:00:00 2001 From: rhjyy Date: Thu, 7 Feb 2019 17:48:34 +0800 Subject: [PATCH 3/4] remove unnecessary output in post-data-concat-test --- test/post-data-concat-test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/post-data-concat-test.js b/test/post-data-concat-test.js index 7fea40a4d..e6c3b7b0e 100644 --- a/test/post-data-concat-test.js +++ b/test/post-data-concat-test.js @@ -22,7 +22,6 @@ describe('post data concat test', function () { MyService: { MyServicePort: { MyOperation: function (arg) { - console.log(arg); check(arg, postdata); return "0"; } From 03fbd2145dff963b588a13caa00986cec1f94424 Mon Sep 17 00:00:00 2001 From: rhjyy Date: Fri, 8 Feb 2019 10:43:01 +0800 Subject: [PATCH 4/4] correct initialization in post-data-concat-test move initialization and finalization into before and after block --- test/post-data-concat-test.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/post-data-concat-test.js b/test/post-data-concat-test.js index e6c3b7b0e..c6d325bfa 100644 --- a/test/post-data-concat-test.js +++ b/test/post-data-concat-test.js @@ -7,6 +7,16 @@ var http = require('http'); describe('post data concat test', function () { + var server = http.createServer(function (req, res) { }); + + before(function () { + server.listen(51515); + }); + + after(function () { + server.close(); + }); + it('should consider the situation about multi-byte character between two tcp packets', function (done) { var check = function (a, b) { if (a && b) { @@ -16,7 +26,6 @@ describe('post data concat test', function () { }; var wsdl = 'test/wsdl/default_namespace.wsdl'; - var server = http.createServer(function (req, res) { }); var xml = fs.readFileSync(wsdl, 'utf8'); var service = { MyService: { @@ -29,7 +38,6 @@ describe('post data concat test', function () { } }; - server.listen(51515); soap.listen(server, '/wsdl', service, xml); var postdata = ""; @@ -42,7 +50,7 @@ describe('post data concat test', function () { }, function (error, client) { assert(!error); client.MyOperation(postdata, function (error, response) { - server.close(); + assert(!error); }); });