File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/utils Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -66,8 +66,27 @@ export const isValidKey = (key: string): boolean => /^"([^"\\]|\\.)*"$/.test(key
66
66
const JSONParser = JSONBigInt ( {
67
67
useNativeBigInt : true ,
68
68
strict : false ,
69
+ alwaysParseAsBig : false ,
70
+ protoAction : 'preserve' ,
71
+ constructorAction : 'preserve'
69
72
} )
70
73
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
+
71
90
export const parseValue = ( value : any , type ?: string ) : any => {
72
91
try {
73
92
if ( typeof value !== 'string' || ! value ) {
@@ -96,7 +115,7 @@ export const parseValue = (value: any, type?: string): any => {
96
115
}
97
116
}
98
117
99
- const parsed = JSONParser . parse ( value )
118
+ const parsed = safeJSONParse ( value )
100
119
101
120
if ( typeof parsed === 'object' && parsed !== null ) {
102
121
if ( Array . isArray ( parsed ) ) {
You can’t perform that action at this time.
0 commit comments