Strip shell/redis-cli prompts from single-line code block copies - #4084
Conversation
The copy-to-clipboard button copied "$ ", "> ", and "127.0.0.1:6379> " prompts verbatim, so pasting a copied command failed until the prompt was removed by hand. Strip these prefixes for single-line blocks, where the line is always just the command; leave multiline blocks (which mix commands and output) untouched. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
🧠 Redis MemoryFound 7 related items from repository history (2 new this commit):
Memory updated at 0151597 |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0467329. Configure here.
| // copied text runs as-is. Multiline blocks mix commands and output, | ||
| // so leave them untouched. | ||
| const text = lines.length === 1 | ||
| ? lines[0].textContent.replace(/^(\s*)(?:\$\s*|>\s*|127\.0\.0\.1:6379>\s*)/, '$1') |
There was a problem hiding this comment.
Prompt strip matches non-prompt prefixes
Medium Severity
The new copy-strip pattern treats a leading $ or > as a prompt even when no space follows, so single-line PHP, shell-variable, and similar snippets lose that first character. Pasting the result then fails. The same pattern is used in both copy handlers.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 0467329. Configure here.
\$\s* and >\s* matched zero trailing spaces, so a bare $ or > with no following space was treated as a prompt too. That stripped the leading character from single-line snippets like PHP ($client = ...) or anything starting with >=. Require at least one space (\s+) so only an actual "$ cmd" / "> cmd" / "127.0.0.1:6379> cmd" prompt gets stripped. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
|
|
This feature can be tested at the following links:
|
andy-stark-redis
left a comment
There was a problem hiding this comment.
All seem to work fine - approved.


The copy-to-clipboard button copied "$ ", "> ", and "127.0.0.1:6379> " prompts verbatim, so pasting a copied command failed until the prompt was removed by hand. Strip these prefixes for single-line blocks, where the line is always just the command; leave multiline blocks (which mix commands and output) untouched.
Note
Low Risk
Client-side copy formatting only; multiline blocks are unchanged and behavior is limited to clipboard text.
Overview
Copy-to-clipboard for docs code blocks now removes common shell and redis-cli prompts (
$,>,127.0.0.1:6379>) when the snippet is a single line, so pasted commands run without manual cleanup.The same rule is applied in
layouts/partials/scripts.html(standalone highlight copy buttons) andstatic/js/codetabs.js(copyCodeToClipboardForCodetabs, after text is assembled from highlighted lines or full code). Multiline snippets are unchanged so mixed command/output blocks still copy verbatim.Reviewed by Cursor Bugbot for commit 0151597. Bugbot is set up for automated code reviews on this repo. Configure here.