Skip to content

Commit 969a52d

Browse files
author
KIvanow
committed
RI-6346 - Value is rounded in array
1 parent 7d4cd5e commit 969a52d

File tree

1 file changed

+20
-1
lines changed
  • redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/utils

1 file changed

+20
-1
lines changed

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/utils/utils.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,27 @@ export const isValidKey = (key: string): boolean => /^"([^"\\]|\\.)*"$/.test(key
6666
const JSONParser = JSONBigInt({
6767
useNativeBigInt: true,
6868
strict: false,
69+
alwaysParseAsBig: false,
70+
protoAction: 'preserve',
71+
constructorAction: 'preserve'
6972
})
7073

74+
const safeJSONParse = (value: string) => {
75+
// Pre-process the string to handle scientific notation
76+
const preprocessed = value.replace(/-?\d+\.?\d*e[+-]?\d+/gi, (match) => {
77+
// Wrap scientific notation numbers in quotes to prevent BigInt conversion
78+
return `"${match}"`
79+
});
80+
81+
return JSONParser.parse(preprocessed, (_key: string, value: any) => {
82+
// Convert quoted scientific notation back to numbers
83+
if (typeof value === 'string' && /^-?\d+\.?\d*e[+-]?\d+$/i.test(value)) {
84+
return Number(value)
85+
}
86+
return value
87+
})
88+
}
89+
7190
export const parseValue = (value: any, type?: string): any => {
7291
try {
7392
if (typeof value !== 'string' || !value) {
@@ -96,7 +115,7 @@ export const parseValue = (value: any, type?: string): any => {
96115
}
97116
}
98117

99-
const parsed = JSONParser.parse(value)
118+
const parsed = safeJSONParse(value)
100119

101120
if (typeof parsed === 'object' && parsed !== null) {
102121
if (Array.isArray(parsed)) {

0 commit comments

Comments
 (0)