Skip to content

Commit

Permalink
New: Reader.create asserts that buffer is a valid buffer, see #695
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Mar 4, 2017
1 parent 4b21e00 commit 0d81a9c
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 41 deletions.
17 changes: 11 additions & 6 deletions dist/light/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/light/protobuf.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/light/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/light/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/light/protobuf.min.js.map

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions dist/minimal/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/minimal/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/minimal/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/minimal/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/minimal/protobuf.min.js.map

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "protobufjs",
"version": "6.6.5",
"version": "6.7.0",
"versionScheme": "~",
"description": "Protocol Buffers for JavaScript (& TypeScript).",
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
Expand Down Expand Up @@ -87,7 +87,7 @@
"tape": "^4.6.3",
"tmp": "0.0.31",
"typescript": "^2.2.1",
"uglify-js": "^2.7.5",
"uglify-js": "^2.8.4",
"vinyl-buffer": "^1.0.0",
"vinyl-fs": "^2.4.4",
"vinyl-source-stream": "^1.1.0"
Expand Down
13 changes: 9 additions & 4 deletions src/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ function Reader(buffer) {
this.len = buffer.length;
}

function create_array(buffer) {
if (buffer instanceof Uint8Array || buffer instanceof Array)
return new Reader(buffer);
throw Error("illegal buffer");
}

/**
* Creates a new reader using the specified buffer.
* @function
Expand All @@ -51,13 +57,12 @@ Reader.create = util.Buffer
return (Reader.create = function create_buffer(buffer) {
return util.Buffer.isBuffer(buffer)
? new BufferReader(buffer)
: new Reader(buffer);
/* istanbul ignore next */
: create_array(buffer);
})(buffer);
}
/* istanbul ignore next */
: function create_array(buffer) {
return new Reader(buffer);
};
: create_array;

Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;

Expand Down

0 comments on commit 0d81a9c

Please sign in to comment.