Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(api): preserve trailing comments after closed dotenv quotes

santhreal6ffdc220f4e6
diff --git a/agent/src/api/helpers.py b/agent/src/api/helpers.py
index 7d6ad539f..0cad87b86 100644
--- a/agent/src/api/helpers.py
+++ b/agent/src/api/helpers.py
@@ -133,11 +133,13 @@ def _ensure_agent_env_file(path: Path | None = None) -> Path:
def _strip_env_value(value: str) -> str:
"""Remove basic dotenv quotes and inline comments."""
value = value.strip()
- # Unquote first so "secret # still" keeps the hash (dotenv quotes shield comments).
+ # Fully quote-wrapped: keep interior `#` (do not treat as comment).
if len(value) >= 2 and value[0] == value[-1] and value[0] in {"'", '"'}:
return value[1:-1].strip()
if " #" in value:
value = value.split(" #", 1)[0].rstrip()
+ if len(value) >= 2 and value[0] == value[-1] and value[0] in {"'", '"'}:
+ value = value[1:-1]
return value.strip()
diff --git a/agent/tests/test_api_infrastructure.py b/agent/tests/test_api_infrastructure.py
index b20ac045b..85a68ecb0 100644
--- a/agent/tests/test_api_infrastructure.py
+++ b/agent/tests/test_api_infrastructure.py
@@ -262,6 +262,12 @@ def test_strip_env_value_quoted_hash_preserves_value():
assert helpers._strip_env_value("'secret # still-part-of-value'") == "secret # still-part-of-value"
+def test_strip_env_value_quoted_then_inline_comment():
+ """Trailing comments after a closed quote must still be stripped."""
+ assert helpers._strip_env_value('"secret" # comment') == "secret"
+ assert helpers._strip_env_value("'secret' # comment") == "secret"
+
+
def test_read_write_env_quoted_hash_roundtrip(tmp_path):
env_file = tmp_path / ".env"
secret = "secret # still-part-of-value"