fix: Don't throw errors for NaN in number operators in the filter component (#9506)

This commit is contained in:
Elias Meire
2024-05-30 13:51:45 +02:00
committed by GitHub
parent e55bf0393a
commit 936bbb2068
6 changed files with 66 additions and 8 deletions

View File

@@ -24,6 +24,10 @@ describe('stringifyExpressionResult()', () => {
expect(stringifyExpressionResult({ ok: true, result: null })).toEqual('');
});
it('should return NaN when result is NaN', () => {
expect(stringifyExpressionResult({ ok: true, result: NaN })).toEqual('NaN');
});
it('should return [empty] message when result is empty string', () => {
expect(stringifyExpressionResult({ ok: true, result: '' })).toEqual('[empty]');
});

View File

@@ -1,7 +1,7 @@
import type { ResolvableState } from '@/types/expressions';
import { ExpressionError, ExpressionParser, type Result } from 'n8n-workflow';
import { i18n } from '@/plugins/i18n';
import { useWorkflowsStore } from '@/stores/workflows.store';
import type { ResolvableState } from '@/types/expressions';
import { ExpressionError, ExpressionParser, type Result } from 'n8n-workflow';
export const isExpression = (expr: unknown) => {
if (typeof expr !== 'string') return false;
@@ -128,5 +128,5 @@ export const stringifyExpressionResult = (result: Result<unknown, Error>): strin
return i18n.baseText('parameterInput.emptyString');
}
return typeof result.result === 'string' ? result.result : JSON.stringify(result.result);
return typeof result.result === 'string' ? result.result : String(result.result);
};