Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,53 @@ describe('convert processors to json', () => {
customProcessor: "aaa\"bbb"
});
});

it('preserves empty string values', () => {
const obj = {
field1: 'normalString',
value: '',
inference_config: '',
field_map: '',
params: '',
pattern_definitions: '',
processor: '',
customOptions: '',
};

const result = convertProccesorsToJson(obj);

expect(result).toEqual({
field1: 'normalString',
value: '',
inference_config: '',
field_map: '',
params: '',
pattern_definitions: '',
processor: '',
});

// Explicitly check that empty strings are preserved and not converted to undefined
expect(result.value).toBe('');
expect(result.inference_config).toBe('');
expect(result.field_map).toBe('');
expect(result.params).toBe('');
expect(result.pattern_definitions).toBe('');
expect(result.processor).toBe('');
});

it('handles null and undefined values correctly', () => {
const obj = {
value: null,
inference_config: undefined,
field_map: 'normalString',
};

const result = convertProccesorsToJson(obj);

expect(result).toEqual({
value: undefined,
inference_config: undefined,
field_map: 'normalString',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,15 @@ const escapeLiteralStrings = (data: string): string[] => {
};

const convertProcessorValueToJson = (data: string): any => {
if (!data) {
if (data === null || data === undefined) {
return undefined;
}

// Preserve empty strings
if (data === '') {
return data;
}

try {
const escapedData = escapeLiteralStrings(data);
return JSON.parse(escapedData.join(''));
Expand Down