fix: preserve empty strings during export (#8727)

This commit is contained in:
Bingbing
2025-05-28 18:31:00 +08:00
committed by Jay Wu
parent e909d3fd2c
commit 3cf71a623b
2 changed files with 50 additions and 6 deletions

View File

@@ -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: ""
`);
});
});

View File

@@ -42,12 +42,7 @@ import {
type WithExportType<T extends models.BaseModel> = 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 {