Skip to content

fix(config): quote .env values containing internal whitespace (#66482) - #66625

Closed
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/env-value-quoting-spaces
Closed

fix(config): quote .env values containing internal whitespace (#66482)#66625
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/env-value-quoting-spaces

Conversation

@AlexFucuson9

Copy link
Copy Markdown
Contributor

Summary

Fixes #66482save_env_value writes unquoted values containing internal spaces, breaking shell-sourcing of .env.

Root cause

_quote_env_value only checked for #, quotes, and leading/trailing whitespace. Internal spaces and tabs were written unquoted, causing shell word-splitting when .env is sourced.

Fix

Add " " in value and "\t" in value to the needs_quoting condition in _quote_env_value.

Impact

Fixes shell-sourcing for paths with spaces:

  • macOS ~/Library/Application Support/...
  • Windows Program Files/...
  • Keys: TERMINAL_SSH_KEY, GOOGLE_CHAT_SERVICE_ACCOUNT_JSON

Testing

  • py_compile passes
  • No behavioral change for values without internal whitespace
  • Values with spaces now correctly quoted: KEY="path with spaces"

_quote_env_value only checked for '#', quotes, and leading/trailing
whitespace when deciding whether to quote a value. Internal spaces
and tabs were written unquoted, which breaks shell-sourcing of .env
(e.g. 'source ~/.hermes/.env') because the shell word-splits on
those spaces.

Real-world impact: paths with spaces (macOS ~/Library/Application
Support/, Windows Program Files/) stored via save_env_value for
TERMINAL_SSH_KEY, GOOGLE_CHAT_SERVICE_ACCOUNT_JSON, etc. would
silently truncate when shell-sourced.

Add internal space and tab to the needs_quoting condition so values
with whitespace are always double-quoted.

Fixes NousResearch#66482

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Summary

Verdict: Approved with Comment

PR #66625fix(config): quote .env values containing internal whitespace

  • Adds whitespace detection (" " and "\t") to the _quote_env_value function in hermes_cli/config.py.
  • Fix is well-scoped: 2-line addition, targeted at a specific bug.
  • Correctly handles tab characters alongside spaces.
  • No security implications; purely config parsing logic.

Suggestions

  • Consider a test case for values containing internal whitespace to prevent regression.

Reviewed by Hermes Agent

@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard area/config Config system, migrations, profiles P2 Medium — degraded but workaround exists sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades duplicate This issue or pull request already exists labels Jul 18, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #66483, the earlier open canonical for quoting .env values with internal whitespace; it also supplies round-trip and idempotence coverage.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

{
"event": "COMMENT",

Code Review Summary

Verdict: Comment (prior COMMENT activity noted)

2-line fix adding space and tab to the quoting-triggering characters in _quote_env_value. Whitespace inside an env value was previously not detected as needing quotes — a bare export KEY=with spaces would be written unquoted and break on re-read. Fix adds or \" \" in value or \"\\t\" in value to the existing quote-detection logic.


Reviewed by Hermes Agent",
"comments": []
}

@teknium1 teknium1 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.

Thanks for isolating the missing quote trigger. The production change targets the live serializer condition in hermes_cli/config.py:7776-7785 and addresses the current-main gap.

Problems

  • This PR adds no regression coverage. Existing serializer tests at tests/hermes_cli/test_config.py:561-608 cover hash/quote/backslash values, not internal spaces or tabs.

Suggested changes

  • If this branch is selected for salvage, add a real save_env_value round-trip test for spaces and tabs. The member-linked canonical duplicate #66483 already carries that coverage alongside the same production behavior.

This is an automated hermes-sweeper review.

Comment thread hermes_cli/config.py
or "'" in value
or value != value.strip()
or " " in value
or " " in value

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.

Please add a regression test for this new serialization trigger. Current tests cover hash/quote/backslash cases but not values containing an internal space or tab; a real save_env_value round-trip would protect the reported behavior.

@OutThisLife

Copy link
Copy Markdown
Collaborator

Superseded by #67192 for #66482 (salvages @pnascimento75's #66483, which adds a shell-source round-trip regression test). Your fix was correct too — closing as redundant to consolidate. Thanks @AlexFucuson9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

save_env_value writes unquoted values with internal spaces - breaks shell-sourcing of .env (core-writer sibling of #57247)

5 participants