mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(core): Handle Date and RegExp correctly in jsonStringify (#5812)
This commit is contained in:
committed by
GitHub
parent
522c790817
commit
4f91525022
@@ -67,17 +67,16 @@ type JSONStringifyOptions = {
|
||||
};
|
||||
|
||||
const replaceCircularReferences = <T>(value: T, knownObjects = new WeakSet()): T => {
|
||||
if (value && typeof value === 'object') {
|
||||
if (knownObjects.has(value)) return '[Circular Reference]' as T;
|
||||
knownObjects.add(value);
|
||||
const copy = (Array.isArray(value) ? [] : {}) as T;
|
||||
for (const key in value) {
|
||||
copy[key] = replaceCircularReferences(value[key], knownObjects);
|
||||
}
|
||||
knownObjects.delete(value);
|
||||
return copy;
|
||||
if (typeof value !== 'object' || value === null || value instanceof RegExp) return value;
|
||||
if ('toJSON' in value && typeof value.toJSON === 'function') return value.toJSON() as T;
|
||||
if (knownObjects.has(value)) return '[Circular Reference]' as T;
|
||||
knownObjects.add(value);
|
||||
const copy = (Array.isArray(value) ? [] : {}) as T;
|
||||
for (const key in value) {
|
||||
copy[key] = replaceCircularReferences(value[key], knownObjects);
|
||||
}
|
||||
return value;
|
||||
knownObjects.delete(value);
|
||||
return copy;
|
||||
};
|
||||
|
||||
export const jsonStringify = (obj: unknown, options: JSONStringifyOptions = {}): string => {
|
||||
|
||||
Reference in New Issue
Block a user