Skip to content

fix(shell): skip env vars with invalid names instead of breaking the shell - #2883

Merged
mikeland73 merged 3 commits into
mainfrom
mikeland73/devbox-shell-export-error
Jun 22, 2026
Merged

fix(shell): skip env vars with invalid names instead of breaking the shell#2883
mikeland73 merged 3 commits into
mainfrom
mikeland73/devbox-shell-export-error

Conversation

@mikeland73

Copy link
Copy Markdown
Collaborator

Summary

A "//" comment key in a devbox.jsonenv block was exported verbatim as export //=..., which zsh rejects with the cryptic not valid in this context: //, breaking the entire devbox shell. exportify and exportifyNushell now skip env vars whose names aren't valid shell identifiers (^[a-zA-Z_][a-zA-Z0-9_]*$) and emit a single clear warning naming the offending keys, instead of generating invalid shell.

How was it tested?

Added unit tests for isValidEnvName and for both export formats skipping invalid names; the full internal/devbox suite, go vet, and go build ./... pass. Reproduced the original failure (export //=xnot valid in this context: //) and confirmed the generated shellenv now passes zsh -n with only valid vars exported and the warning shown on stderr.

Community Contribution License

All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.

By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.

…shell
A "//" comment key in a devbox.json env block was exported verbatim as
`export //=...`, which zsh rejects with a cryptic "not valid in this
context: //" and breaks the entire shell. exportify/exportifyNushell now
skip names that aren't valid shell identifiers and emit a single clear
warning naming them.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings June 21, 2026 18:15

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request hardens Devbox’s shell environment export generation by filtering out invalid environment variable names (e.g., JSON “comment keys” like "//") so devbox shell / devbox shellenv no longer emits syntactically invalid shell code and breaks shells like zsh.

Changes:

  • Add env var name validation (isValidEnvName) and a consolidated warning for skipped invalid keys.
  • Update exportify and exportifyNushell to skip exporting invalid identifiers instead of generating invalid shell syntax.
  • Add unit tests covering env name validation and the “skip invalid names” behavior for both export formats.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

FileDescription
internal/devbox/envvars.goAdds env var name validation, warning emission, and skips invalid env names in both POSIX and nushell export generators.
internal/devbox/envvars_test.goAdds unit tests for env name validation and verifying invalid names are not emitted in export output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadinternal/devbox/envvars.go
Comment threadinternal/devbox/envvars.go
Comment threadinternal/devbox/envvars_test.go Outdated
mikeland73and others added 2 commits June 21, 2026 11:23
Address review feedback on invalid env name handling:
- exportify/exportifyNushell/warnInvalidEnvNames now take an io.Writer
so warnings respect --quiet and caller-provided stderr instead of
always writing to os.Stderr
- anchor the validation regex in the warning text (^...$) to show the
entire name must conform
- assert //ccache is skipped in TestExportifySkipsInvalidNames
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mikeland73
mikeland73 merged commit 6475211 into mainJun 22, 2026
20 checks passed
@mikeland73
mikeland73 deleted the mikeland73/devbox-shell-export-error branch June 22, 2026 01:25
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@mikeland73