Skip to content

fix(api,framework): Undefined variables parsing #8041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/src/app/shared/helpers/liquid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ const stringifyDataStructureWithSingleQuotes = (value: unknown, spaces: number =

return valueEscapedNewLines;
} else {
return String(value);
return value == null ? '' : String(value as unknown);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this shortcut, but because this is very sensitive part i wonder if we should go with the more explicit version "value === null || value === undefined" instead.
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's different with that version ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String(value) when value is undefined returns undefined. Isn't that the reason we started this PR in the first place?

}
};
2 changes: 1 addition & 1 deletion packages/framework/src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ describe('Novu Client', () => {
const emailExecutionResult = await client.executeWorkflow(event);

expect(emailExecutionResult.outputs).toEqual({
body: 'Hi undefined',
body: 'Hi ',
subject: 'Test subject',
});
});
Expand Down
8 changes: 4 additions & 4 deletions packages/framework/src/utils/liquid.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe('defaultOutputEscape', () => {
expect(defaultOutputEscape(true)).toBe('true');
expect(defaultOutputEscape(false)).toBe('false');
expect(defaultOutputEscape(null)).toBe('null');
expect(defaultOutputEscape(undefined)).toBe('undefined');
expect(defaultOutputEscape(undefined)).toBe('');
});
});

Expand Down Expand Up @@ -342,15 +342,15 @@ describe('stringifyDataStructureWithSingleQuotes', () => {
expect(converted).toStrictEqual('true');
});

it('should convert null to a string without single quotes', () => {
it('should convert null to an empty string', () => {
const myTestNull = null;
const converted = stringifyDataStructureWithSingleQuotes(myTestNull);
expect(converted).toStrictEqual('null');
expect(converted).toStrictEqual('');
});

it('should convert undefined to an empty string', () => {
const myTestUndefined = undefined;
const converted = stringifyDataStructureWithSingleQuotes(myTestUndefined);
expect(converted).toStrictEqual('undefined');
expect(converted).toStrictEqual('');
});
});
4 changes: 2 additions & 2 deletions packages/framework/src/utils/liquid.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function defaultOutputEscape(output: unknown): string {
else if (typeof output === 'string' && output.includes('\n')) {
return output.replace(/\n/g, '\\n');
} else {
return String(output);
return output === undefined ? '' : String(output as unknown);
}
}

Expand All @@ -34,7 +34,7 @@ export const stringifyDataStructureWithSingleQuotes = (value: unknown, spaces: n

return valueEscapedNewLines;
} else {
return String(value);
return value == null ? '' : String(value as unknown);
}
};

Expand Down
Loading