π Bug Description
Multi-line strings containing special shell characters get corrupted when passed through command-stream's $ template literal with the echo command. This is a critical issue for scripts that need to handle complex text content like README files, configuration files, or any multi-line text with special characters.
π΄ Impact
This bug makes it impossible to reliably write multi-line content with special characters using shell commands through command-stream. It affects any use case involving:
- README files with code examples
- Configuration files with paths and variables
- Documentation with markdown formatting
- Any text containing backticks, quotes, dollar signs, or backslashes
π Detailed Problem Analysis
When using echo with multi-line strings containing special characters, the shell interprets these characters instead of treating them as literal text:
- Backticks (`) get interpreted as command substitution
- Dollar signs ($) trigger variable expansion
- Quotes (single and double) get mangled during escaping
- Backslashes (\) are processed as escape characters
- Newlines may be lost or corrupted
π Reproduction Steps
const complexContent = \`# Test Repository
This is a test repository with \\\`backticks\\\` and "quotes".
## Code Example
\\\`\\\`\\\`javascript
const message = "Hello, World!";
console.log(\\\`Message: \\\${message}\\\`);
\\\`\\\`\\\`
## Special Characters
- Single quotes: 'test'
- Double quotes: "test"
- Backticks: \\\`test\\\`
- Dollar signs: $100
- Backslashes: C:\\\\Windows\\\\System32\`;
// β This fails or corrupts the content
await $\`echo "\${complexContent}" > \${testFile}\`;
// The content gets mangled due to shell interpretation
β
Expected Behavior
The content should be written to the file exactly as specified, preserving all special characters without any shell interpretation.
β Actual Behavior
- Content gets corrupted due to shell escaping issues
- Special characters are interpreted by the shell
- The resulting file contains mangled or incomplete text
- May cause syntax errors if the content includes code
π§ Workarounds
Workaround 1: Use fs.writeFile (Recommended)
// β
Most reliable for any content
await fs.writeFile(testFile, complexContent);
Workaround 2: Use heredoc with quoted delimiter
// β
Prevents shell interpretation
await $\`cat << 'EOF' > \${testFile}
\${complexContent}
EOF\`;
Workaround 3: Avoid echo with complex strings
Simply don't use echo for multi-line or complex content - use Node.js fs methods instead.
π― Suggested Fix
- Implement proper escaping for multi-line strings in command-stream
- Consider detecting multi-line content and automatically using a safer method
- Add warnings in documentation about this limitation
- Provide a built-in safe write method that handles all content types
π Test Coverage
The issue includes a comprehensive test script that:
- Sets up complex multi-line content with various special characters
- Attempts to write it using echo (demonstrates the bug)
- Verifies content corruption
- Shows working workarounds
π References
π Checklist for Fix
π Bug Description
Multi-line strings containing special shell characters get corrupted when passed through command-stream's
$template literal with theechocommand. This is a critical issue for scripts that need to handle complex text content like README files, configuration files, or any multi-line text with special characters.π΄ Impact
This bug makes it impossible to reliably write multi-line content with special characters using shell commands through command-stream. It affects any use case involving:
π Detailed Problem Analysis
When using
echowith multi-line strings containing special characters, the shell interprets these characters instead of treating them as literal text:π Reproduction Steps
β Expected Behavior
The content should be written to the file exactly as specified, preserving all special characters without any shell interpretation.
β Actual Behavior
π§ Workarounds
Workaround 1: Use fs.writeFile (Recommended)
Workaround 2: Use heredoc with quoted delimiter
Workaround 3: Avoid echo with complex strings
Simply don't use
echofor multi-line or complex content - use Node.js fs methods instead.π― Suggested Fix
π Test Coverage
The issue includes a comprehensive test script that:
π References
π Checklist for Fix