Add literal() function to preserve apostrophes in shell arguments#148
Open
Add literal() function to preserve apostrophes in shell arguments#148
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 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This reverts commit 9fd2362.
Member
Author
🤖 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. |
Member
Author
🔄 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. |
Member
Author
🤖 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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