Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ Proxy.prototype.invoke = function(method, args, callback) {
};

if (this.username) {
options.auth = {
user: this.username,
pass: this.password,
sendImmediately: true
};
// Use iso-8859-1 character encoding for basic authentication parameters
options.headers['Authorization'] = 'Basic '
+ Buffer.from(this.username + ':' + this.password, 'latin1').toString('base64');
}

var req = require(this.protocol).request(options, function(res) {
Expand Down Expand Up @@ -87,4 +85,4 @@ Proxy.prototype.invoke = function(method, args, callback) {

};

module.exports = Proxy;
module.exports = Proxy;
43 changes: 36 additions & 7 deletions lib/reader2.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,51 @@ 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)
this.reader = new BufferReader(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();
}
};

Expand Down Expand Up @@ -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();
}
};
Expand Down
4 changes: 2 additions & 2 deletions lib/writer2.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@ Writer.prototype.writeList = function(data) {
};

Writer.prototype.writeType = function(data) {
this.writeString(data);
if (this.typeRefs.hasOwnProperty(data)) {
this.writeInt(this.typeRefs[data]);
} else {
this.typeRefs[data] = Object.keys(this.typeRefs).length;
this.writeString(data);
}
return this;
};
Expand All @@ -388,4 +388,4 @@ function cap(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}

module.exports = Writer;
module.exports = Writer;