Skip to content

Commit

Permalink
Version Bump: 2.13.0 (#900)
Browse files Browse the repository at this point in the history
Backported serializer fix

Signed-off-by: Theo Truong <[email protected]>
Co-authored-by: Hailong Cui <[email protected]>
  • Loading branch information
nhtruong and Hailong-am authored Nov 12, 2024
1 parent 4b6f16f commit d8de993
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/Serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 3 additions & 17 deletions test/unit/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions test/unit/serializer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit d8de993

Please sign in to comment.