aboutsummaryrefslogtreecommitdiff
path: root/js/map.js
diff options
context:
space:
mode:
authorAdam Cozzette <acozzette@gmail.com>2018-05-25 15:26:18 -0700
committerGitHub <noreply@github.com>2018-05-25 15:26:18 -0700
commitedaaea01f69cb9927813a5fe55093b8faacebb97 (patch)
treeea2c0cfe72f25c79e6bb0e0d7f8f4da320cc3c4a /js/map.js
parent6f723a6624de0e0f9b1ae16ae002e678613e07b8 (diff)
parentd1af029104e9b594a99209484914b822addb08fa (diff)
downloadprotobuf-edaaea01f69cb9927813a5fe55093b8faacebb97.tar.gz
protobuf-edaaea01f69cb9927813a5fe55093b8faacebb97.tar.bz2
protobuf-edaaea01f69cb9927813a5fe55093b8faacebb97.zip
Merge pull request #4687 from acozzette/js-map-parsing-fix
Fixed JS parsing of unspecified map keys
Diffstat (limited to 'js/map.js')
-rw-r--r--js/map.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/js/map.js b/js/map.js
index 7b5b2c38..2fb14837 100644
--- a/js/map.js
+++ b/js/map.js
@@ -443,7 +443,8 @@ jspb.Map.prototype.serializeBinary = function(
/**
* Read one key/value message from the given BinaryReader. Compatible as the
* `reader` callback parameter to jspb.BinaryReader.readMessage, to be called
- * when a key/value pair submessage is encountered.
+ * when a key/value pair submessage is encountered. If the Key is undefined,
+ * we should default it to 0.
* @template K, V
* @param {!jspb.Map} map
* @param {!jspb.BinaryReader} reader
@@ -457,12 +458,17 @@ jspb.Map.prototype.serializeBinary = function(
* readMessage, in which case the second callback arg form is used.
*
* @param {?function(V,!jspb.BinaryReader)=} opt_valueReaderCallback
- * The BinaryReader parsing callback for type V, if V is a message type.
+ * The BinaryReader parsing callback for type V, if V is a message type
+ *
+ * @param {K=} opt_defaultKey
+ * The default value for the type of map keys. Accepting map
+ * entries with unset keys is required for maps to be backwards compatible
+ * with the repeated message representation described here: goo.gl/zuoLAC
*
*/
jspb.Map.deserializeBinary = function(map, reader, keyReaderFn, valueReaderFn,
- opt_valueReaderCallback) {
- var key = undefined;
+ opt_valueReaderCallback, opt_defaultKey) {
+ var key = opt_defaultKey;
var value = undefined;
while (reader.nextField()) {
@@ -470,6 +476,7 @@ jspb.Map.deserializeBinary = function(map, reader, keyReaderFn, valueReaderFn,
break;
}
var field = reader.getFieldNumber();
+
if (field == 1) {
// Key.
key = keyReaderFn.call(reader);