diff --git a/packages/bruno-app/src/components/Sidebar/ImportCollection/FileTab.js b/packages/bruno-app/src/components/Sidebar/ImportCollection/FileTab.js index 949af58d9..daba50d44 100644 --- a/packages/bruno-app/src/components/Sidebar/ImportCollection/FileTab.js +++ b/packages/bruno-app/src/components/Sidebar/ImportCollection/FileTab.js @@ -23,7 +23,7 @@ const convertFileToObject = async (file) => { return JSON.parse(text); } - const parsed = jsyaml.load(text); + const parsed = jsyaml.load(text, { schema: jsyaml.JSON_SCHEMA }); if (typeof parsed !== 'object' || parsed === null) { throw new Error(); } diff --git a/packages/bruno-app/src/utils/importers/common.js b/packages/bruno-app/src/utils/importers/common.js index 4a6477afc..8ed2c9c0c 100644 --- a/packages/bruno-app/src/utils/importers/common.js +++ b/packages/bruno-app/src/utils/importers/common.js @@ -224,7 +224,7 @@ export const fetchAndValidateApiSpecFromUrl = ({ url }) => { ipcRenderer .invoke('renderer:fetch-api-spec', url) .then(async (res) => { - const data = await jsyaml.load(res); + const data = await jsyaml.load(res, { schema: jsyaml.JSON_SCHEMA }); const specType = getCollectionSpecType(data); resolve({ data, specType, rawContent: res }); }) diff --git a/packages/bruno-converters/src/insomnia/insomnia-to-bruno.js b/packages/bruno-converters/src/insomnia/insomnia-to-bruno.js index 38c452f28..35c9aa505 100644 --- a/packages/bruno-converters/src/insomnia/insomnia-to-bruno.js +++ b/packages/bruno-converters/src/insomnia/insomnia-to-bruno.js @@ -34,7 +34,7 @@ const addSuffixToDuplicateName = (item, index, allItems) => { const regexVariable = new RegExp('{{.*?}}', 'g'); const normalizeVariables = (value) => { - value = value || ''; + value = String(value ?? ''); const variables = value.match(regexVariable) || []; each(variables, (variable) => { value = value.replace(variable, variable.replace('_.', '').replaceAll(' ', '')); diff --git a/tests/import/insomnia/fixtures/insomnia-v5-dates.yaml b/tests/import/insomnia/fixtures/insomnia-v5-dates.yaml new file mode 100644 index 000000000..fd64c5719 --- /dev/null +++ b/tests/import/insomnia/fixtures/insomnia-v5-dates.yaml @@ -0,0 +1,52 @@ +type: collection.insomnia.rest/5.0 +schema_version: "5.1" +name: Date Type Test +meta: + id: wrk_date_test + created: 1776845227518 + modified: 1776845227518 +collection: + - url: http://example.com/test + name: Date Request + meta: + id: req_date_test_001 + created: 1776845260825 + modified: 1778146479401 + isPrivate: false + sortKey: -1776845260825 + method: GET + parameters: + - name: date + value: 2024-01-01 + disabled: false + - name: is_active + value: "false" + disabled: false + - name: limit + value: "0" + disabled: false + - name: version + value: "2.0" + disabled: false + - name: count + value: 42 + disabled: false + settings: + renderRequestBody: true + encodeUrl: true + followRedirects: global + cookies: + send: true + store: true + rebuildPath: true +environments: + name: Base + meta: + id: env_date_test_001 + created: 1776845235974 + modified: 1776845235974 + isPrivate: false + data: + expiry_date: 2024-12-31 + max_retries: "3" + enabled: "true" diff --git a/tests/import/insomnia/import-insomnia-v5-date-types.spec.ts b/tests/import/insomnia/import-insomnia-v5-date-types.spec.ts new file mode 100644 index 000000000..97ef02379 --- /dev/null +++ b/tests/import/insomnia/import-insomnia-v5-date-types.spec.ts @@ -0,0 +1,56 @@ +import { test, expect } from '../../../playwright'; +import * as path from 'path'; +import * as fs from 'fs'; +import { closeAllCollections, importCollection } from '../../utils/page'; + +test.describe('Import Insomnia Collection - date types preserved', () => { + test.afterEach(async ({ page }) => { + await closeAllCollections(page); + }); + + test('should keep date-like strings and quoted values intact through the full FileTab.js import flow', async ({ + page, + createTmpDir + }) => { + const insomniaFile = path.resolve(__dirname, 'fixtures', 'insomnia-v5-dates.yaml'); + const collectionName = 'Date Type Test'; + const collectionDir = await createTmpDir('insomnia-dates-test'); + + await importCollection(page, insomniaFile, collectionDir, { + expectedCollectionName: collectionName + }); + + const requestFilePath = path.join(collectionDir, collectionName, 'Date Request.yml'); + const yamlContent = fs.readFileSync(requestFilePath, 'utf8'); + + expect(yamlContent).toContain(` params: + - name: date + value: 2024-01-01 + type: query + - name: is_active + value: "false" + type: query + - name: limit + value: "0" + type: query + - name: version + value: "2.0" + type: query + - name: count + value: "42" + type: query +`); + + const envFilePath = path.join(collectionDir, collectionName, 'environments', 'Base.yml'); + const envContent = fs.readFileSync(envFilePath, 'utf8'); + + expect(envContent).toContain(`variables: + - name: expiry_date + value: 2024-12-31 + - name: max_retries + value: "3" + - name: enabled + value: "true" +`); + }); +});