From 4cae0672114cf4012788f13e83285513d8211ebd Mon Sep 17 00:00:00 2001 From: Martin Dirichs Date: Fri, 3 Mar 2017 15:00:46 +0100 Subject: [PATCH 1/3] Corrected the way basic authtication parameters are supplied to HttpClient --- lib/proxy.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/proxy.js b/lib/proxy.js index b0b3b86..a260dfa 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -48,11 +48,7 @@ Proxy.prototype.invoke = function(method, args, callback) { }; if (this.username) { - options.auth = { - user: this.username, - pass: this.password, - sendImmediately: true - }; + options.auth = this.username + ':' + this.password; } var req = require(this.protocol).request(options, function(res) { @@ -87,4 +83,4 @@ Proxy.prototype.invoke = function(method, args, callback) { }; -module.exports = Proxy; \ No newline at end of file +module.exports = Proxy; From 513c797e9f3d0cd201c329e9727b8a498091aaa4 Mon Sep 17 00:00:00 2001 From: Martin Dirichs Date: Thu, 9 Mar 2017 17:43:18 +0100 Subject: [PATCH 2/3] Corrected handling of double values with up to three decimal places (code 0x5f) --- lib/reader2.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/reader2.js b/lib/reader2.js index 6c22e07..cddfcc4 100644 --- a/lib/reader2.js +++ b/lib/reader2.js @@ -389,9 +389,11 @@ Reader.prototype.readDouble = function(data) { return this.reader.nextInt8(); else if (code === 0x5e) return this.reader.nextInt16BE(); - else if (code === 0x5f) - return this.reader.nextFloatBE(); - else if (code === 0x44) { + else if (code === 0x5f) { + // While the specification suggests reading a FloatBE here, + // this is the way how it's handled by the Java implementation + return this.reader.nextInt32BE() * 0.001; + } else if (code === 0x44) { return this.reader.nextDoubleBE(); } }; From bb5527d29a4c417e0e8036babe0e27014d4dbd1c Mon Sep 17 00:00:00 2001 From: Martin Dirichs Date: Wed, 29 Mar 2017 09:27:19 +0200 Subject: [PATCH 3/3] Corrected handling of UTF8 encoded string; this addition is inspired by a contribution of pandazki --- lib/reader2.js | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/reader2.js b/lib/reader2.js index cddfcc4..0295523 100644 --- a/lib/reader2.js +++ b/lib/reader2.js @@ -229,6 +229,33 @@ Reader.prototype.readClassDef = function(data) { } }; +Reader.prototype.readUTF8String = function(len) { + + if (len === 0) + return ""; + + var startPos = this.reader.tell(), byteLength; + + while (len--) { + var head = this.reader.nextUInt8(); + if (head < 0x80) { + continue; + } else if ((head & 0xe0) === 0xc0) { + this.reader.move(1); + } else if ((head & 0xf0) === 0xe0) { + this.reader.move(2); + } else if ((head & 0xf8) === 0xf0) { + this.reader.move(3); + } else { + throw new Error("String is not in valid UTF-8 format"); + } + } + + byteLength = this.reader.tell() - startPos; + this.reader.seek(startPos); + + return this.reader.nextString(byteLength, 'utf8'); +} Reader.prototype.readString = function(data) { if (data) @@ -236,17 +263,17 @@ Reader.prototype.readString = function(data) { var code = this.reader.nextUInt8(); if (code >= 0 && code < 32) { - return this.reader.nextString(code); + return this.readUTF8String(code); } else if (code >= 0x30 && code <= 0x33) { this.reader.move(-1); var len = this.reader.nextUInt16BE() - 0x3000; - return this.reader.nextString(len); + return this.readUTF8String(len); } else if (code === 0x53) { var len = this.reader.nextUInt16BE(); - return this.reader.nextString(len); + return this.readUTF8String(len); } else if (code === 0x52) { var len = this.reader.nextUInt16BE(); - return this.reader.nextString(len) + this.readString(); + return this.readUTF8String(len) + this.readString(); } };