Skip to content

Commit

Permalink
Merge 4489651 into 8aa73da
Browse files Browse the repository at this point in the history
  • Loading branch information
mverzakov committed Sep 15, 2016
2 parents 8aa73da + 4489651 commit 1c5079b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/type-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ TypeObject.prototype.writeBytes = function (bytes, useWordLength) {
if (this.isReadonly()) {
return false;
}
var bLength = useWordLength ? bytes.length / 4 : bytes.length;
var realLength = typeof bytes == 'string' ? unescape(encodeURIComponent(bytes)).length : bytes.length;
var bLength = useWordLength ? realLength / 4 : realLength;
var isShort = bLength < (useWordLength ? 0x7F : 0xFE);
var buffer = new Buffer(isShort ? 1 : 4);
var offset = 0;
Expand All @@ -149,7 +150,7 @@ TypeObject.prototype.writeBytes = function (bytes, useWordLength) {
this._writeBytes(bytes);
// add padding if needed
if (!useWordLength) {
var padding = (offset + bytes.length) % 4;
var padding = (offset + realLength) % 4;
if (padding > 0) {
buffer = new Buffer(4 - padding);
buffer.fill(0);
Expand Down

0 comments on commit 1c5079b

Please sign in to comment.