fix(core): Serialize dates and regexps when reading from augmented objects (#6086)

https://community.n8n.io/t/workflows-fail-when-triggered-but-succeed-when-run-manually/25575
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-04-26 09:11:13 +00:00 committed by GitHub
parent 390841bbf0
commit a4eb46acc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -90,6 +90,11 @@ export function augmentObject<T extends object>(data: T): T {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const value = Reflect.get(target, key, receiver);
if (typeof value !== 'object' || value === null) return value;
if (value instanceof RegExp) return value.toString();
if ('toJSON' in value && typeof value.toJSON === 'function') return value.toJSON() as T;
const newValue = augment(value);
if (newValue !== value) {
Object.assign(newData, { [key]: newValue });

View file

@ -233,8 +233,8 @@ describe('AugmentObject', () => {
a: 9111,
b: '9222',
c: 3,
d: date,
r: regexp,
d: date.toJSON(),
r: regexp.toString(),
});
});