fix: convert non-string variable values to strings during postman import (#7476)

This commit is contained in:
Pooja
2026-03-16 12:05:24 +05:30
committed by GitHub
parent 83ddfc33d2
commit 7e0b8d9f9d
2 changed files with 38 additions and 1 deletions

View File

@@ -159,7 +159,7 @@ const importCollectionLevelVariables = (variables, requestObject) => {
const vars = variables.filter((v) => !(v.key == null && v.value == null)).map((v) => ({
uid: uuid(),
name: (v.key ?? '').replace(invalidVariableCharacterRegex, '_'),
value: v.value ?? '',
value: v.value == null ? '' : typeof v.value === 'string' ? v.value : JSON.stringify(v.value),
enabled: true
}));

View File

@@ -238,6 +238,43 @@ describe('postman-collection', () => {
]);
});
it('should convert non-string variable values to strings', async () => {
const collectionWithNonStringVars = {
info: {
name: 'Non-String Variable Demo',
_postman_id: 'abcd1234-5678-90ef-ghij-1234567890ab',
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
},
variable: [
{ key: 'timeout', value: 5000 },
{ key: 'enabled', value: true },
{ key: 'user', value: { id: 1, name: 'Alice' } }
],
item: [
{
name: 'Sample Request',
request: {
method: 'GET',
url: {
raw: 'https://postman-echo.com/get',
protocol: 'https',
host: ['postman-echo', 'com'],
path: ['get']
}
}
}
]
};
const brunoCollection = await postmanToBruno(collectionWithNonStringVars);
const vars = brunoCollection.root.request.vars.req;
expect(vars).toHaveLength(3);
expect(vars[0]).toMatchObject({ name: 'timeout', value: '5000' });
expect(vars[1]).toMatchObject({ name: 'enabled', value: 'true' });
expect(vars[2]).toMatchObject({ name: 'user', value: '{"id":1,"name":"Alice"}' });
});
it('should handle empty variables', async () => {
const collectionWithEmptyVars = {
info: {