From 6652cca64225abccb006b53b9c9d3e8747db47ad Mon Sep 17 00:00:00 2001 From: max-melhuish-depop Date: Fri, 12 Dec 2025 06:22:29 +0000 Subject: [PATCH] Removed filtering of empty strings from url paths when importing from postman collection (#5868) * removed filtering of empty strings from url paths when importing from postman collection * revert accidental non-pr changes * chore: remove console logs --------- Co-authored-by: Max Melhuish <238188923+max-melhuish-depop@users.noreply.github.com> Co-authored-by: Bijin A B --- .../src/postman/postman-to-bruno.js | 2 +- .../postman-to-bruno/postman-to-bruno.spec.js | 159 ++++++++++++++++++ 2 files changed, 160 insertions(+), 1 deletion(-) diff --git a/packages/bruno-converters/src/postman/postman-to-bruno.js b/packages/bruno-converters/src/postman/postman-to-bruno.js index b3d6238c6..170a7bafb 100644 --- a/packages/bruno-converters/src/postman/postman-to-bruno.js +++ b/packages/bruno-converters/src/postman/postman-to-bruno.js @@ -84,7 +84,7 @@ const constructUrlFromParts = (url) => { const { protocol = 'http', host, path, port, query, hash } = url || {}; const hostStr = Array.isArray(host) ? host.filter(Boolean).join('.') : host || ''; - const pathStr = Array.isArray(path) ? path.filter(Boolean).join('/') : path || ''; + const pathStr = Array.isArray(path) ? path.join('/') : path || ''; const portStr = port ? `:${port}` : ''; const queryStr = query && Array.isArray(query) && query.length > 0 diff --git a/packages/bruno-converters/tests/postman/postman-to-bruno/postman-to-bruno.spec.js b/packages/bruno-converters/tests/postman/postman-to-bruno/postman-to-bruno.spec.js index 180174868..28b944d67 100644 --- a/packages/bruno-converters/tests/postman/postman-to-bruno/postman-to-bruno.spec.js +++ b/packages/bruno-converters/tests/postman/postman-to-bruno/postman-to-bruno.spec.js @@ -79,6 +79,165 @@ describe('postman-collection', () => { ]); }); + it('should successfully translate a URL path array with no empty elements', async () => { + const collectionWithFalsyVars = { + info: { + _postman_id: '7f91bbd8-cb97-41ac-8d0b-e1fcd8bb4ce9', + name: 'collection with falsy vars', + schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json' + }, + variable: [ + { + type: 'string' + }, + { + key: '', + type: 'string' + }, + { + value: '', + type: 'string' + }, + { + key: '', + value: '', + type: 'string' + } + ], + item: [ + { + name: 'Request with all settings', + protocolProfileBehavior: { + maxRedirects: 10, + followRedirects: false, + disableUrlEncoding: true + }, + request: { + method: 'GET', + header: [], + url: { + protocol: 'https', + host: ['httpbin', 'org'], + path: ['api', 'v1', 'resource'] + } + } + } + ] + }; + + const brunoCollection = await postmanToBruno(collectionWithFalsyVars); + + expect(brunoCollection.items.map((item) => item.request.url)).toEqual([ + 'https://httpbin.org/api/v1/resource' + ]); + }); + + it('should not mutate a URL path with an empty element representing a trailing slash', async () => { + const collectionWithFalsyVars = { + info: { + _postman_id: '7f91bbd8-cb97-41ac-8d0b-e1fcd8bb4ce9', + name: 'collection with falsy vars', + schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json' + }, + variable: [ + { + type: 'string' + }, + { + key: '', + type: 'string' + }, + { + value: '', + type: 'string' + }, + { + key: '', + value: '', + type: 'string' + } + ], + item: [ + { + name: 'Request with all settings', + protocolProfileBehavior: { + maxRedirects: 10, + followRedirects: false, + disableUrlEncoding: true + }, + request: { + method: 'GET', + header: [], + url: { + protocol: 'https', + host: ['httpbin', 'org'], + path: ['api', 'v1', 'resource', ''] + } + } + } + ] + }; + + const brunoCollection = await postmanToBruno(collectionWithFalsyVars); + + expect(brunoCollection.items.map((item) => item.request.url)).toEqual([ + 'https://httpbin.org/api/v1/resource/' + ]); + }); + + it('should not mutate a URL path with an empty element representing a trailing slash', async () => { + const collectionWithFalsyVars = { + info: { + _postman_id: '7f91bbd8-cb97-41ac-8d0b-e1fcd8bb4ce9', + name: 'collection with falsy vars', + schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json' + }, + variable: [ + { + type: 'string' + }, + { + key: '', + type: 'string' + }, + { + value: '', + type: 'string' + }, + { + key: '', + value: '', + type: 'string' + } + ], + item: [ + { + name: 'Request with all settings', + protocolProfileBehavior: { + maxRedirects: 10, + followRedirects: false, + disableUrlEncoding: true + }, + request: { + method: 'GET', + header: [], + url: { + protocol: 'https', + host: ['httpbin', 'org'], + path: ['api', '', 'resource'] + } + } + } + ] + }; + + const brunoCollection = await postmanToBruno(collectionWithFalsyVars); + + expect(brunoCollection.items.map((item) => item.request.url)).toEqual([ + 'https://httpbin.org/api//resource' + ]); + }); + it('should handle empty variables', async () => { const collectionWithEmptyVars = { info: {