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; diff --git a/lib/reader2.js b/lib/reader2.js index 6c22e07..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(); } }; @@ -389,9 +416,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(); } };