-
Notifications
You must be signed in to change notification settings - Fork 1
Add literal() function to preserve apostrophes in shell arguments #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #141
Fixes #141 - Apostrophes in text arguments are over-escaped, appearing as triple quotes (''') when stored literally by receiving programs. ## Problem When passing text containing apostrophes through command-stream, the default quote() function uses Bash's '\'' escaping pattern. While correct for shell interpretation, when the receiving program (like gh CLI) passes text to an API that stores it literally, the escape sequences appear as visible characters ('''). ## Solution Add two new functions: - `literal(value)` - Mark text for double-quote escaping, preserving apostrophes while still escaping shell-dangerous characters ($, `, \, ") - `quoteLiteral(value)` - Low-level function for manual command building ## Usage ```javascript import { $, literal } from 'command-stream'; // Problem: default escaping await $`gh release create --notes ${text}`; // didn't → didn'''t // Solution: use literal() await $`gh release create --notes ${literal(text)}`; // didn't stays didn't ``` ## Changes - js/src/$.mjs: Add quoteLiteral() and literal() functions - js/tests/$.test.mjs: Add 15 new tests for quoteLiteral and literal - README.md: Add documentation for literal() and quoteLiteral() - docs/case-studies/issue-141/: Case study with root cause analysis - experiments/: Test scripts for verification - eslint.config.js: Add experiments/ to lenient rules 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
This reverts commit 9fd2362.
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
🔄 Auto-restart 1/3Detected uncommitted changes from previous run. Starting new session to review and commit them. Uncommitted files: Auto-restart will stop after changes are committed or after 2 more iterations. Please wait until working session will end and give your feedback. |
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
Summary
Fixes #141 - Apostrophes in text arguments are over-escaped, appearing as triple quotes (
''') when stored literally by receiving programs.Problem
When passing text containing apostrophes through command-stream, the default
quote()function uses Bash's'\''escaping pattern. While this is correct for shell interpretation, when the receiving program (likeghCLI) passes text to an API that stores it literally, the escape sequences appear as visible characters (''').For example:
Solution
Add two new functions:
literal(value)- Mark text for double-quote escaping, preserving apostrophes while still escaping shell-dangerous characters ($,`,\,")quoteLiteral(value)- Low-level function for manual command buildingUsage
How
literal()differs fromraw()and default quoting:'$ \"`'\''escapedliteral()raw()Changes
Core Implementation
quoteLiteral()andliteral()functions with proper double-quote escapingTests
quoteLiteral()unit tests (apostrophes, double quotes, dollar signs, backticks, backslashes, empty strings, null/undefined, safe strings, arrays)literal()unit testsDocumentation
literal()andquoteLiteral(), including comparison table and usage examplesCase Study
Experiments
Configuration
Test Results
All tests pass:
The new
literal()function correctly preserves all test cases:🤖 Generated with Claude Code