From 3cf71a623b76d9dd2b3e97bf6f482e42807de5b6 Mon Sep 17 00:00:00 2001 From: Bingbing Date: Wed, 28 May 2025 18:31:00 +0800 Subject: [PATCH] fix: preserve empty strings during export (#8727) --- .../src/common/__tests__/insomnia-v5.test.ts | 49 +++++++++++++++++++ packages/insomnia/src/common/insomnia-v5.ts | 7 +-- 2 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 packages/insomnia/src/common/__tests__/insomnia-v5.test.ts diff --git a/packages/insomnia/src/common/__tests__/insomnia-v5.test.ts b/packages/insomnia/src/common/__tests__/insomnia-v5.test.ts new file mode 100644 index 0000000000..348c87adc8 --- /dev/null +++ b/packages/insomnia/src/common/__tests__/insomnia-v5.test.ts @@ -0,0 +1,49 @@ +import { describe, expect, it } from 'vitest'; + +import * as models from '../../models'; +import { getInsomniaV5DataExport } from '../insomnia-v5'; + +describe('getInsomniaV5DataExport', () => { + it('should preserve empty string environments', async () => { + const workspace = await models.workspace.create({ + _id: 'wrk_id', + name: 'Workspace Name', + created: 0, + modified: 0, + description: 'workspace description', + }); + + await models.environment.create({ + _id: 'env_id', + name: 'Environment Name', + parentId: workspace._id, + created: 0, + modified: 0, + data: { + foo: 'bar', + empty: '', + }, + }); + + const result = await getInsomniaV5DataExport({ workspaceId: 'wrk_id', includePrivateEnvironments: false }); + + expect(result).toEqual(`type: collection.insomnia.rest/5.0 +name: Workspace Name +meta: + id: wrk_id + created: 0 + modified: 0 + description: workspace description +environments: + name: Environment Name + meta: + id: env_id + created: 0 + modified: 0 + isPrivate: false + data: + foo: bar + empty: "" +`); + }); +}); diff --git a/packages/insomnia/src/common/insomnia-v5.ts b/packages/insomnia/src/common/insomnia-v5.ts index 44d1620f8a..5aebda3f5d 100644 --- a/packages/insomnia/src/common/insomnia-v5.ts +++ b/packages/insomnia/src/common/insomnia-v5.ts @@ -42,12 +42,7 @@ import { type WithExportType = T & { _type: string }; function filterEmptyValue(value: string | number | boolean | null | undefined) { - return ( - value !== null && - value !== undefined && - value !== '' && - !(typeof value === 'object' && Object.keys(value).length === 0) - ); + return value !== null && value !== undefined && !(typeof value === 'object' && Object.keys(value).length === 0); } function removeEmptyFields(data: any): any {