Skip to content

Conversation

Pragadesh-45
Copy link
Contributor

@Pragadesh-45 Pragadesh-45 commented Aug 28, 2025

Fixes: #4518 #1581 #1953
Related to: #4827

Description

This PR adds support for multiline environment variables by updating the environment parsing logic in envToJson and jsonToEnv has been enhanced to handle multiline values using triple quotes (''') for better readability and formatting.

Comprehensive tests have been added, including integration tests for round-trip conversion between JSON and .bru formats, as well as expanded unit tests covering edge cases like special characters, empty values, and global environment variables.

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

COLLECTION ENVIRONMENTS
image
image

GLOBAL ENVIRONMENTS
image
image

if (value && (value.includes('\n') || value.includes('\r'))) {
// Use multiline format with triple quotes
const indentedValue = value.split('\n').map(line => ` ${line}`).join('\n');
return ` ${prefix}${name}: '''\n${indentedValue}\n'''`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pragadesh-45 i guess we will need to add indentation, ''' should start indented, I guess we should also indent the multiline value as shown, rather than it being inline with abc

vars : {
    abc: '''
      {
       key:value
      }
    '''
}

If we don't indent the value, it may look like

vars : {
    abc: '''
    key:value
    key2: value
    '''
}

let me know your thoughts on this, i believe i did with the indentation within grpc, we should have a conversation on this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, i'll update the pr

@@ -113,15 +116,43 @@ const sem = grammar.createSemantics().addAttribute('ast', {
},
pair(_1, key, _2, _3, _4, value, _5) {
let res = {};
res[key.ast] = value.ast ? value.ast.trim() : '';
res[key.ast] = value.ast !== undefined ? value.ast : '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pragadesh44-Bruno what is the impact on removing the trim(), I think this can cause some inconsistencies or regression as this has been used for quite some time!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have added this to preserve the white spaces since it is important for the values to be handled properly (especially for multiline)

@Pragadesh-45 Pragadesh-45 marked this pull request as draft September 1, 2025 14:42
- Updated SingleLineEditor to allow newlines when `allowNewlines` prop is true, otherwise runs the handler on Shift-Enter.
- Modified grammar in envToJson to support multiline text blocks with triple quotes.
- Updated jsonToEnv to format values with newlines using triple quotes for better readability.
- refactor: replace `SingleLineEditor` with `MultilineEditor` to support newLines
@Pragadesh-45 Pragadesh-45 force-pushed the feat/multiline-values-for-env-vars branch from 83a4195 to 99ed018 Compare September 1, 2025 14:48
- Simplified multiline string processing in envToJson by removing unnecessary checks and directly slicing leading spaces.
- Introduced getValueString function in jsonToEnv to handle multiline strings with proper indentation and formatting.
- Added indentString4 utility function for consistent 4-space indentation across the codebase.
@pull-request-size pull-request-size bot added size/XL and removed size/L labels Sep 2, 2025
- Updated grammar to define start and end for multiline text blocks.
- Simplified value extraction for multiline strings by directly returning the AST.
- Improved indentation handling by removing leading spaces from multiline content.
@Pragadesh-45 Pragadesh-45 marked this pull request as ready for review September 2, 2025 15:15
Pragadesh-45 and others added 7 commits September 3, 2025 21:09
- Implemented tests to read and create multiline environment variables.
- Verified successful request execution and response handling for multiline JSON data.
- Added necessary collection and environment files for testing.
- Deleted the `bruMultiline.spec.js` file as it is no longer needed.
- This cleanup helps maintain a lean test suite and reduces redundancy.
- Updated `jsonToEnv` to use `indentString` for consistent indentation of variable names and values.
- Simplified `getValueString` to trim trailing whitespace and ensure proper formatting of multiline values.
- Removed unnecessary parameters for cleaner utility functions.
@Pragadesh-45 Pragadesh-45 force-pushed the feat/multiline-values-for-env-vars branch from 752748e to a616d81 Compare September 5, 2025 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Environment disappears when JSON in a variable's value
3 participants