From ff266ee883a868a9bbf9f7adc0a6ca6b6397703b Mon Sep 17 00:00:00 2001 From: Aaron Son Date: Tue, 29 Dec 2020 17:47:33 -0800 Subject: [PATCH] js/binary/utils.js: Fix jspb.utils.joinUnsignedDecimalString to work with negative bitsLow and low but non-zero bitsHigh parameter. --- js/binary/decoder_test.js | 3 +++ js/binary/utils.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/js/binary/decoder_test.js b/js/binary/decoder_test.js index 9900e65bc5ca..8fce993f5d81 100644 --- a/js/binary/decoder_test.js +++ b/js/binary/decoder_test.js @@ -315,6 +315,9 @@ describe('binaryDecoderTest', function() { // 64-bit extremes, not in dev guide. {original: '9223372036854775807', zigzag: '18446744073709551614'}, {original: '-9223372036854775808', zigzag: '18446744073709551615'}, + // None of the above catch: bitsLow < 0 && bitsHigh > 0 && bitsHigh < 0x1FFFFF. + // The following used to be broken. + {original: '72000000000', zigzag: '144000000000'}, ]; var encoder = new jspb.BinaryEncoder(); testCases.forEach(function(c) { diff --git a/js/binary/utils.js b/js/binary/utils.js index 6cd15e36445d..4d743310cf55 100644 --- a/js/binary/utils.js +++ b/js/binary/utils.js @@ -511,7 +511,7 @@ jspb.utils.joinUnsignedDecimalString = function(bitsLow, bitsHigh) { // Skip the expensive conversion if the number is small enough to use the // built-in conversions. if (bitsHigh <= 0x1FFFFF) { - return '' + (jspb.BinaryConstants.TWO_TO_32 * bitsHigh + bitsLow); + return '' + jspb.utils.joinUint64(bitsLow, bitsHigh); } // What this code is doing is essentially converting the input number from