diff --git a/packages/bruno-electron/src/store/env-secrets.js b/packages/bruno-electron/src/store/env-secrets.js index 1b962cdbd..e70a1c064 100644 --- a/packages/bruno-electron/src/store/env-secrets.js +++ b/packages/bruno-electron/src/store/env-secrets.js @@ -2,6 +2,8 @@ const _ = require('lodash'); const Store = require('electron-store'); const { encryptStringSafe } = require('../utils/encryption'); +const posixifyPath = (p) => (p ? p.replace(/\\/g, '/') : p); + /** * Sample secrets store file * @@ -28,6 +30,7 @@ class EnvironmentSecretsStore { } storeEnvSecrets(collectionPathname, environment) { + const normalizedPathname = posixifyPath(collectionPathname); const envVars = []; _.each(environment.variables, (v) => { if (v.secret) { @@ -39,12 +42,12 @@ class EnvironmentSecretsStore { }); const collections = this.store.get('collections') || []; - const collection = _.find(collections, (c) => c.path === collectionPathname); + const collection = _.find(collections, (c) => posixifyPath(c.path) === normalizedPathname); // if collection doesn't exist, create it, add the environment and save if (!collection) { collections.push({ - path: collectionPathname, + path: normalizedPathname, environments: [ { name: environment.name, @@ -57,6 +60,8 @@ class EnvironmentSecretsStore { return; } + collection.path = normalizedPathname; + // if collection exists, check if environment exists // if environment doesn't exist, add the environment and save collection.environments = collection.environments || []; @@ -77,8 +82,9 @@ class EnvironmentSecretsStore { } getEnvSecrets(collectionPathname, environment) { + const normalizedPathname = posixifyPath(collectionPathname); const collections = this.store.get('collections') || []; - const collection = _.find(collections, (c) => c.path === collectionPathname); + const collection = _.find(collections, (c) => posixifyPath(c.path) === normalizedPathname); if (!collection) { return []; } @@ -92,8 +98,9 @@ class EnvironmentSecretsStore { } renameEnvironment(collectionPathname, oldName, newName) { + const normalizedPathname = posixifyPath(collectionPathname); const collections = this.store.get('collections') || []; - const collection = _.find(collections, (c) => c.path === collectionPathname); + const collection = _.find(collections, (c) => posixifyPath(c.path) === normalizedPathname); if (!collection) { return; } @@ -108,8 +115,9 @@ class EnvironmentSecretsStore { } deleteEnvironment(collectionPathname, environmentName) { + const normalizedPathname = posixifyPath(collectionPathname); const collections = this.store.get('collections') || []; - const collection = _.find(collections, (c) => c.path === collectionPathname); + const collection = _.find(collections, (c) => posixifyPath(c.path) === normalizedPathname); if (!collection) { return; } diff --git a/packages/bruno-electron/src/utils/workspace-config.js b/packages/bruno-electron/src/utils/workspace-config.js index 51d095176..7e0c6d900 100644 --- a/packages/bruno-electron/src/utils/workspace-config.js +++ b/packages/bruno-electron/src/utils/workspace-config.js @@ -6,7 +6,7 @@ const { generateUidBasedOnHash } = require('./common'); const { withLock, getWorkspaceLockKey } = require('./workspace-lock'); // Normalize Windows backslash paths to forward slashes for cross-platform compatibility. -const posixifyPath = (p) => p.replace(/\\/g, '/'); +const posixifyPath = (p) => (p ? p.replace(/\\/g, '/') : p); const WORKSPACE_TYPE = 'workspace'; const OPENCOLLECTION_VERSION = '1.0.0';