Skip to content

Commit

Permalink
fix a problem about Multi-Byte character (#1042)
Browse files Browse the repository at this point in the history
* 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.

* 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.

* remove unnecessary output in post-data-concat-test

* correct initialization in post-data-concat-test

move initialization and finalization into before and after block
  • Loading branch information
rhjyy authored and jsdevel committed Feb 8, 2019
1 parent 2bed4c7 commit 5b45068
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
59 changes: 59 additions & 0 deletions test/post-data-concat-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

var fs = require('fs');
var soap = require('..');
var assert = require('assert');
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) {
assert(a === b);
done();
}
};

var wsdl = 'test/wsdl/default_namespace.wsdl';
var xml = fs.readFileSync(wsdl, 'utf8');
var service = {
MyService: {
MyServicePort: {
MyOperation: function (arg) {
check(arg, postdata);
return "0";
}
}
}
};

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) {
assert(!error);
});
});

});
});

0 comments on commit 5b45068

Please sign in to comment.