You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(deployment): remove unnecessary env var escaping and document best practices
**Changes:**
1. **health-check.sh**: Removed unnecessary manual bracket escaping for CRITICAL_SERVICES
- Environment variables don't undergo shell parsing or glob expansion
- Manual escaping with ${VAR//\[/\\[} was unnecessary and fragile
- Now uses raw $CRITICAL_SERVICES passed via env, preserving valid JSON
2. **IMPLEMENTATION_GUIDE.md**: Added comprehensive "Shell Escaping Best Practices" section
- When to use `printf '%q'` (positional arguments only)
- When escaping is NOT needed (environment variables)
- SSH command quoting strategies (single vs double quotes)
- Deprecated manual bracket escaping patterns
- Complete examples and quick reference table
- Common pitfalls to avoid
**Rationale:**
Environment variables passed via `env VAR="value"` to SSH don't undergo shell
parsing or glob expansion, so manual escaping is unnecessary. Only positional
arguments passed to remote scripts need escaping via `printf '%q'`.
**Related:** Fixes similar to detect-removed-stacks.sh glob expansion bug
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>
**Why**: Positional arguments undergo shell parsing and glob expansion. Without escaping, characters like `[]`, `*`, `?` are interpreted as glob patterns.
322
+
323
+
#### When Escaping is NOT Needed (Environment Variables)
324
+
325
+
**DO NOT** escape variables passed via `env` or environment variable assignment:
326
+
327
+
```bash
328
+
# Correct: No escaping needed for environment variables
**Why**: Environment variables don't undergo shell parsing or glob expansion. The value is passed directly to the remote shell environment. Values must remain valid (e.g., valid JSON) for the remote script to parse.
336
+
337
+
#### SSH Command Quoting Strategies
338
+
339
+
**Single vs Double Quotes**: Choose based on where variable expansion should occur.
340
+
341
+
```bash
342
+
# Pattern 1: Double quotes (expansion on local shell)
0 commit comments