Accept Buffer on UserAgent.encode
This commit is contained in:
parent
68c7966bef
commit
5ada61cbe1
|
@ -62,8 +62,8 @@ exports.parse = function(str) {
|
|||
/**
|
||||
* Encode user agent into `var_str` Buffer. Most underlying software
|
||||
* comes first.
|
||||
* @param {(Object[]|string[]|string)} software - List of software to
|
||||
* encode or just raw user agent string
|
||||
* @param {(Object[]|string[]|string|Buffer)} software - List of
|
||||
* software to encode or just raw user agent string/Buffer
|
||||
* @return {Buffer} Encoded user agent.
|
||||
* @function
|
||||
* @static
|
||||
|
@ -83,6 +83,8 @@ var encode = exports.encode = function(software) {
|
|||
return str;
|
||||
}).join("/");
|
||||
ua = "/" + ua + "/";
|
||||
} else if (Buffer.isBuffer(software)) {
|
||||
return software;
|
||||
} else {
|
||||
ua = software;
|
||||
}
|
||||
|
@ -90,7 +92,7 @@ var encode = exports.encode = function(software) {
|
|||
};
|
||||
|
||||
/**
|
||||
* Encode bitmessage's user agent.
|
||||
* Encode bitmessage's library user agent.
|
||||
* @return {Buffer} Encoded user agent.
|
||||
*/
|
||||
exports.encodeSelf = function() {
|
||||
|
@ -98,8 +100,8 @@ exports.encodeSelf = function() {
|
|||
};
|
||||
|
||||
/**
|
||||
* Encode user agent with bitmessage's user agent underneath. Most
|
||||
* underlying software comes first.
|
||||
* Encode user agent with bitmessage's library user agent underneath.
|
||||
* Most underlying software comes first.
|
||||
* @param {(Object[]|string[]|Object|string)} software - List of
|
||||
* software to encode
|
||||
* @return {Buffer} Encoded user agent.
|
||||
|
|
|
@ -1327,5 +1327,14 @@ describe("High-level classes", function() {
|
|||
expect(UserAgent.parse("/test").length).to.equal(0);
|
||||
expect(UserAgent.parse("test/").length).to.equal(0);
|
||||
});
|
||||
|
||||
it("should accept raw Buffer on encode", function() {
|
||||
var enc = UserAgent.encodeSelfWith("test:0.0.1");
|
||||
enc = UserAgent.encode(enc);
|
||||
var software = UserAgent.parse(UserAgent.decode(enc).str);
|
||||
expect(software[0].name).to.equal("bitmessage");
|
||||
expect(software[1]).to.deep.equal({name: "test", version: "0.0.1"});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user