Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converter: Fix 'bytes' field decoding into an empty array, now decoded into an empty Buffer #1020

Merged
merged 5 commits into from
Apr 30, 2018
Merged
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
12 changes: 9 additions & 3 deletions src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,15 @@ converter.toObject = function toObject(mtype) {
("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", prop)
("}else")
("d%s=o.longs===String?%j:%i", prop, field.typeDefault.toString(), field.typeDefault.toNumber());
else if (field.bytes) gen
("d%s=o.bytes===String?%j:%s", prop, String.fromCharCode.apply(String, field.typeDefault), "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]");
else gen
else if (field.bytes) {
var arrayDefault = "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]";
gen
("if(o.bytes===String)d%s=%j", prop, String.fromCharCode.apply(String, field.typeDefault))
("else{")
("d%s=%s", prop, arrayDefault)
("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
("}")
} else gen
("d%s=%j", prop, field.typeDefault); // also messages (=null)
} gen
("}");
Expand Down