Commit 82a4e4e3 authored by Yilun Chong's avatar Yilun Chong

Fix js reader.js's skipGroup

parent 8705adc2
...@@ -389,7 +389,7 @@ jspb.BinaryReader.prototype.skipFixed64Field = function() { ...@@ -389,7 +389,7 @@ jspb.BinaryReader.prototype.skipFixed64Field = function() {
*/ */
jspb.BinaryReader.prototype.skipGroup = function() { jspb.BinaryReader.prototype.skipGroup = function() {
// Keep a stack of start-group tags that must be matched by end-group tags. // Keep a stack of start-group tags that must be matched by end-group tags.
var nestedGroups = [this.nextField_]; var previousField = this.nextField_;
do { do {
if (!this.nextField()) { if (!this.nextField()) {
goog.asserts.fail('Unmatched start-group tag: stream EOF'); goog.asserts.fail('Unmatched start-group tag: stream EOF');
...@@ -397,19 +397,17 @@ jspb.BinaryReader.prototype.skipGroup = function() { ...@@ -397,19 +397,17 @@ jspb.BinaryReader.prototype.skipGroup = function() {
return; return;
} }
if (this.nextWireType_ == if (this.nextWireType_ ==
jspb.BinaryConstants.WireType.START_GROUP) {
// Nested group start.
nestedGroups.push(this.nextField_);
} else if (this.nextWireType_ ==
jspb.BinaryConstants.WireType.END_GROUP) { jspb.BinaryConstants.WireType.END_GROUP) {
// Group end: check that it matches top-of-stack. // Group end: check that it matches top-of-stack.
if (this.nextField_ != nestedGroups.pop()) { if (this.nextField_ != previousField) {
goog.asserts.fail('Unmatched end-group tag'); goog.asserts.fail('Unmatched end-group tag');
this.error_ = true; this.error_ = true;
return; return;
} }
return;
} }
} while (nestedGroups.length > 0); this.skipField();
} while (true);
}; };
......
...@@ -680,8 +680,10 @@ describe('binaryReaderTest', function() { ...@@ -680,8 +680,10 @@ describe('binaryReaderTest', function() {
var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
writer.writeGroup(5, dummyMessage, function() { writer.writeGroup(5, dummyMessage, function() {
writer.writeInt64(42, 42); writer.writeInt64(42, 42);
writer.writeString(43, 'The quick brown fox jumps over the lazy dog');
writer.writeGroup(6, dummyMessage, function() { writer.writeGroup(6, dummyMessage, function() {
writer.writeInt64(84, 42); writer.writeInt64(84, 42);
writer.writeString(85, 'The quick brown fox jumps over the lazy dog');
}); });
}); });
......
...@@ -22,5 +22,5 @@ ...@@ -22,5 +22,5 @@
"url": "https://github.com/google/protobuf/tree/master/js" "url": "https://github.com/google/protobuf/tree/master/js"
}, },
"author": "Google Protocol Buffers Team", "author": "Google Protocol Buffers Team",
"license" : "BSD-3-Clause" "license": "BSD-3-Clause"
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment