aboutsummaryrefslogtreecommitdiff
path: root/js/binary
diff options
context:
space:
mode:
authorAdam Cozzette <acozzette@google.com>2017-03-06 15:12:19 -0800
committerAdam Cozzette <acozzette@google.com>2017-03-06 15:37:40 -0800
commit651ba62ab5a9c35e157380e2fd89cf77febb47b9 (patch)
tree2aa83e2d2ac475a1b74132b9a07a82dba67f752e /js/binary
parent008ff033ef3308512c1da2b7cdadf50a6296251a (diff)
downloadprotobuf-651ba62ab5a9c35e157380e2fd89cf77febb47b9.tar.gz
protobuf-651ba62ab5a9c35e157380e2fd89cf77febb47b9.tar.bz2
protobuf-651ba62ab5a9c35e157380e2fd89cf77febb47b9.zip
JS: ensure that extension values are serialized even if they're falsy
There was a bug where for JavaScript we would only serialize an extension value if it evaluated as truthy, which meant that values like 0 would get silently dropped (even in proto2, where field presence is significant). This fixes issue #2605, and takes care of the output of toObject() in addition to the binary format.
Diffstat (limited to 'js/binary')
-rw-r--r--js/binary/proto_test.js6
1 files changed, 2 insertions, 4 deletions
diff --git a/js/binary/proto_test.js b/js/binary/proto_test.js
index f86dc645..f5e1b6bb 100644
--- a/js/binary/proto_test.js
+++ b/js/binary/proto_test.js
@@ -283,8 +283,7 @@ function checkAllFields(original, copy) {
* @param {!proto.jspb.test.TestExtendable} msg
*/
function checkExtensions(msg) {
- assertEquals(-42,
- msg.getExtension(proto.jspb.test.extendOptionalInt32));
+ assertEquals(0, msg.getExtension(proto.jspb.test.extendOptionalInt32));
assertEquals(-0x7fffffff00000000,
msg.getExtension(proto.jspb.test.extendOptionalInt64));
assertEquals(0x80000000,
@@ -512,8 +511,7 @@ describe('protoBinaryTest', function() {
* @param {proto.jspb.test.TestExtendable} msg
*/
function fillExtensions(msg) {
- msg.setExtension(
- proto.jspb.test.extendOptionalInt32, -42);
+ msg.setExtension(proto.jspb.test.extendOptionalInt32, 0);
msg.setExtension(
proto.jspb.test.extendOptionalInt64, -0x7fffffff00000000);
msg.setExtension(