fix: handle falsy values in Postman environment and collection variables (#4924)

* fix: handle falsy values in Postman environment and collection variables

* Updated the `postman-env-to-bruno-env` and `postman-to-bruno` converters to handle cases where variable keys or values are falsy, ensuring they default to empty strings.
* Added unit tests to verify the correct handling of falsy values in both environment and collection variables.

* fix: filter out null/undefined keys and values in Postman variable imports

* Updated the `postman-env-to-bruno-env` and `postman-to-bruno` converters to filter out variables with null keys and values during import.
* Removed redundant test cases for empty variables in the corresponding unit tests.
This commit is contained in:
sanish chirayath
2025-06-24 15:58:29 +05:30
committed by GitHub
parent bbf4ad6b98
commit 2bbfb28090
4 changed files with 153 additions and 7 deletions

View File

@@ -6,14 +6,14 @@ const isSecret = (type) => {
return type === 'secret';
};
const importPostmanEnvironmentVariables = (brunoEnvironment, values) => {
const importPostmanEnvironmentVariables = (brunoEnvironment, values = []) => {
brunoEnvironment.variables = brunoEnvironment.variables || [];
each(values, (i) => {
each(values.filter(i => !(i.key == null && i.value == null)), (i) => {
const brunoEnvironmentVariable = {
uid: uuid(),
name: i.key.replace(invalidVariableCharacterRegex, '_'),
value: i.value,
name: (i.key ?? '').replace(invalidVariableCharacterRegex, '_'),
value: i.value ?? '',
enabled: i.enabled,
secret: isSecret(i.type)
};

View File

@@ -119,10 +119,10 @@ const importScriptsFromEvents = (events, requestObject) => {
};
const importCollectionLevelVariables = (variables, requestObject) => {
const vars = variables.map((v) => ({
const vars = variables.filter(v => !(v.key == null && v.value == null)).map((v) => ({
uid: uuid(),
name: v.key.replace(invalidVariableCharacterRegex, '_'),
value: v.value,
name: (v.key ?? '').replace(invalidVariableCharacterRegex, '_'),
value: v.value ?? '',
enabled: true
}));