[PR #5439] [MERGED] fix(js-sandbox): resolve environment variable fallback behavior #5207

Closed
opened 2026-03-17 02:40:40 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5439
Author: @chhaviG22
Created: 10/3/2025
Status: Merged
Merged: 10/28/2025
Merged by: @jamesgeorge007

Base: nextHead: fix/env-var-fallback


📝 Commits (5)

  • 96cf152 fix: fallback to initialValue for environment vars with empty currentValue in pre/post-request scripts
  • 4ff8ee9 Update packages/hoppscotch-js-sandbox/src/utils/shared.ts
  • 6317fce Update packages/hoppscotch-js-sandbox/src/utils/shared.ts
  • 5c5b402 chore: cleanup
  • af1ad0b chore: improve fallback logic and add comprehensive test coverage

📊 Changes

4 files changed (+1005 additions, -34 deletions)

View changed files

packages/hoppscotch-js-sandbox/src/__tests__/combined/env-fallback-behavior.spec.ts (+864 -0)
📝 packages/hoppscotch-js-sandbox/src/cage-modules/utils/base-inputs.ts (+6 -0)
📝 packages/hoppscotch-js-sandbox/src/types/index.ts (+64 -9)
📝 packages/hoppscotch-js-sandbox/src/utils/shared.ts (+71 -25)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5439 **Author:** [@chhaviG22](https://github.com/chhaviG22) **Created:** 10/3/2025 **Status:** ✅ Merged **Merged:** 10/28/2025 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `next` ← **Head:** `fix/env-var-fallback` --- ### 📝 Commits (5) - [`96cf152`](https://github.com/hoppscotch/hoppscotch/commit/96cf1521bd07aeb57f0f6c6f34bc12d62b2b214d) fix: fallback to initialValue for environment vars with empty currentValue in pre/post-request scripts - [`4ff8ee9`](https://github.com/hoppscotch/hoppscotch/commit/4ff8ee9e5689dc548959ede8bab046ab62afdf88) Update packages/hoppscotch-js-sandbox/src/utils/shared.ts - [`6317fce`](https://github.com/hoppscotch/hoppscotch/commit/6317fce5d02e4b6dda0ad886414f6b4d4e811f7b) Update packages/hoppscotch-js-sandbox/src/utils/shared.ts - [`5c5b402`](https://github.com/hoppscotch/hoppscotch/commit/5c5b402aa98f8a7251aaa3cfa1c76d3c23027753) chore: cleanup - [`af1ad0b`](https://github.com/hoppscotch/hoppscotch/commit/af1ad0b2ad54ca3ca5f9e51da498b12d43fedb47) chore: improve fallback logic and add comprehensive test coverage ### 📊 Changes **4 files changed** (+1005 additions, -34 deletions) <details> <summary>View changed files</summary> ➕ `packages/hoppscotch-js-sandbox/src/__tests__/combined/env-fallback-behavior.spec.ts` (+864 -0) 📝 `packages/hoppscotch-js-sandbox/src/cage-modules/utils/base-inputs.ts` (+6 -0) 📝 `packages/hoppscotch-js-sandbox/src/types/index.ts` (+64 -9) 📝 `packages/hoppscotch-js-sandbox/src/utils/shared.ts` (+71 -25) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:40:40 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5207
No description provided.