From d8de99378515193b7cd02316cbf686299cd618fc Mon Sep 17 00:00:00 2001 From: "Theo N. Truong" Date: Tue, 12 Nov 2024 12:01:46 -0700 Subject: [PATCH] Version Bump: 2.13.0 (#900) Backported serializer fix Signed-off-by: Theo Truong Co-authored-by: Hailong Cui --- CHANGELOG.md | 12 ++++++++---- lib/Serializer.js | 2 +- package.json | 2 +- test/unit/client.test.js | 20 +++----------------- test/unit/serializer.test.js | 31 +++++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0c313f81..837b67480 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,16 +5,20 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] ### Added ### Dependencies +### Changed +### Deprecated +### Removed +### Fixed +### Security + +## [2.13.0] +### Dependencies - Bumps `micromatch` from 4.0.7 to 4.0.8 - Bumps `simple-statistics` from 7.8.4 to 7.8.5 - Bumps `simple-git` from 3.25.0 to 3.26.0 - Bumps `@types/node` from 22.5.0 to 22.5.2 -### Changed -### Deprecated -### Removed ### Fixed - Upgrade `JSON11` from 1.1.2 to 2.0.0 to ensure UTF-8 safety when stringifying JSON data -### Security ## [2.12.0] ### Dependencies diff --git a/lib/Serializer.js b/lib/Serializer.js index 2636a53d0..2864718d8 100644 --- a/lib/Serializer.js +++ b/lib/Serializer.js @@ -101,7 +101,7 @@ class Serializer { if ( numeralsAreNumbers && typeof val === 'number' && - (val < Number.MAX_SAFE_INTEGER || val > Number.MAX_SAFE_INTEGER) + (val < Number.MIN_SAFE_INTEGER || val > Number.MAX_SAFE_INTEGER) ) { numeralsAreNumbers = false; } diff --git a/package.json b/package.json index 2273e19ce..f5ba79877 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ } }, "homepage": "https://www.opensearch.org/", - "version": "2.12.0", + "version": "2.13.0", "versionCanary": "7.10.0-canary.6", "keywords": [ "opensearch", diff --git a/test/unit/client.test.js b/test/unit/client.test.js index e1d3557f2..b2b92b5f1 100644 --- a/test/unit/client.test.js +++ b/test/unit/client.test.js @@ -1036,27 +1036,13 @@ test('Content length too big (string)', (t) => { test('Content length exceeds max heap limit', (t) => { t.plan(4); - const percentage = 0.8; - const HEAP_SIZE_LIMIT_WITH_BUFFER = Number( - require('v8').getHeapStatistics().heap_size_limit * percentage - ); - const contentLength = buffer.constants.MAX_STRING_LENGTH - 1; + const percentage = 0.01; + const HEAP_SIZE_LIMIT = require('v8').getHeapStatistics().heap_size_limit; + const contentLength = Math.round(HEAP_SIZE_LIMIT * percentage + 1); const memoryCircuitBreaker = { enabled: true, maxPercentage: percentage, }; - // Simulate allocation of bytes - const memoryAllocations = []; - while (process.memoryUsage().heapUsed + contentLength <= HEAP_SIZE_LIMIT_WITH_BUFFER) { - const allocation = 50 * 1024 * 1024; // 50MB - const numbers = allocation / 8; - const arr = []; - arr.length = numbers; - for (let i = 0; i < numbers; i++) { - arr[i] = i; - } - memoryAllocations.push(arr); - } class MockConnection extends Connection { request(params, callback) { diff --git a/test/unit/serializer.test.js b/test/unit/serializer.test.js index 1773fce07..41bb466f3 100644 --- a/test/unit/serializer.test.js +++ b/test/unit/serializer.test.js @@ -79,6 +79,37 @@ test('Long numerals enabled', (t) => { t.match(res, `"[ ${longNegative.toString()}, ${longPositive.toString()} ]"`); }); +test('Long numerals enabled and json not includes large numbers', (t) => { + t.plan(2); + const s = new Serializer({ enableLongNumeralSupport: true }); + const longPositive = BigInt(Number.MAX_SAFE_INTEGER) * 2n; // eslint-disable-line no-undef + const longNegative = BigInt(Number.MIN_SAFE_INTEGER) * 2n; // eslint-disable-line no-undef + const json = + `{` + + // The space before and after the values, and the lack of spaces before comma are intentional + `"false-positive-1": "෴${longNegative.toString()}", ` + + `"false-positive-2": "[ ߷${longPositive.toString()} ]", ` + + `"false-positive-3": "\\": ֍${longPositive.toString()}\\"", ` + + `"false-positive-4": "෴߷֍${longPositive.toString()}", ` + + `"normal-number": 2024,` + + `"max-safe-integer": ${Number.MAX_SAFE_INTEGER},` + + `"min-safe-integer": ${Number.MIN_SAFE_INTEGER}` + + `}`; + const obj = s.deserialize(json); + const res = s.serialize(obj); + t.same(obj, { + 'normal-number': 2024, + 'max-safe-integer': `${Number.MAX_SAFE_INTEGER}`, + 'min-safe-integer': `${Number.MIN_SAFE_INTEGER}`, + 'false-positive-4': `෴߷֍${longPositive.toString()}`, + 'false-positive-3': `": ֍${longPositive.toString()}"`, + 'false-positive-2': `[ ߷${longPositive.toString()} ]`, + 'false-positive-1': `෴${longNegative.toString()}`, + }); + // The space before and after the values, and the lack of spaces before comma are intentional + t.equal(res.replace(/\s+/g, ''), json.replace(/\s+/g, '')); +}); + test('long numerals not enabled', (t) => { t.plan(5); const s = new Serializer({ enableLongNumeralSupport: false });