Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@chhaviG22
Copy link
Contributor

@chhaviG22 chhaviG22 commented Oct 3, 2025

Closes #5437

This PR addresses the issue where environment variables with empty currentValue don't fall back to their initialValue in pre-request or post-request scripts. It ensures that the correct value is returned as expected.

What's Changed

  • Fixed the logic to ensure environment variables return initialValue when currentValue is empty or unset.
  • Updated the behaviour to return an empty string only when both initialValue and currentValue are not set.
  • Added type clarifications: introduced SandboxEnvironmentVariable to distinguish between internal sandbox types (which can be arrays/objects/primitives) and the external API boundary (which always uses strings).

Notes to Reviewers
Check the fallback behaviour for environment variables with both initialValue and an empty currentValue.
Review the changes made in the REST tab to confirm correct functionality for pre/post-request scripts.

The type system changes are purely for clarity - they separate the internal sandbox representation (which can hold complex types for pm namespace compatibility) from the external API (which serialises everything to strings). No functional changes to the type system, just better documentation.

Let me know if there are any additional edge cases to cover or feedback to address.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where environment variables with empty currentValue were not properly falling back to their initialValue in pre/post-request scripts. The fix ensures that when currentValue is empty or unset, the initialValue is used instead.

  • Updated environment variable resolution logic to use initialValue as fallback when currentValue is empty
  • Applied the fix to both direct value retrieval and template string parsing functions
  • Ensures consistent behavior across different environment variable access patterns

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@chhaviG22 chhaviG22 closed this Oct 3, 2025
@chhaviG22 chhaviG22 reopened this Oct 3, 2025
@nivedin nivedin changed the base branch from main to patch October 6, 2025 09:42
@jamesgeorge007 jamesgeorge007 self-assigned this Oct 7, 2025
@jamesgeorge007 jamesgeorge007 changed the base branch from patch to next October 28, 2025 17:22
@jamesgeorge007 jamesgeorge007 removed the request for review from liyasthomas October 28, 2025 17:22
- Merge latest changes alongside conflict resolution.
- Add `null` check to fallback conditions in `shared.ts`.
- Introduce `SandboxEnvironmentVariable` type to clarify internal vs external types.
- Add comprehensive test suite covering fallback behavior across namespaces.
- Document type flow from `SandboxValue` (internal) to string (external API).
@jamesgeorge007 jamesgeorge007 changed the title fix: fallback to initialValue for environment vars with empty currentValue in pre/post-request scripts fix(js-sandbox): resolve environment variable fallback behavior Oct 28, 2025
Copy link
Member

@jamesgeorge007 jamesgeorge007 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @chhaviG22. I've pushed a few changes to base this on top of the recent architectural changes as part of the scripting revamp efforts, alongside comprehensive test coverage. This will be going live in the upcoming major release.

@jamesgeorge007 jamesgeorge007 merged commit 9a4e5a7 into hoppscotch:next Oct 28, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Environment vars with empty currentValue should fallback to initialValue in pre/post request scripts

3 participants