Skip to content

Strip shell/redis-cli prompts from single-line code block copies - #4084

Merged
paoloredis merged 2 commits into
mainfrom
DOC-5845-copy-button-fix
Sep 23, 2026
Merged

paoloredis merged 2 commits into
mainfrom
DOC-5845-copy-button-fix

Conversation

@paoloredis

@paoloredis paoloredis commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

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) and static/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.

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>
@github-actions

github-actions Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

DOC-5845

@github-actions

github-actions Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

🧠 Redis Memory

Found 7 related items from repository history (2 new this commit):

Memory updated at 0151597

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread layouts/partials/scripts.html Outdated
// 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')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

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>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@paoloredis

Copy link
Copy Markdown
Collaborator Author

This feature can be tested at the following links:

@paoloredis
paoloredis requested a review from a team September 23, 2026 13:11

@andy-stark-redis andy-stark-redis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All seem to work fine - approved.

@dwdougherty dwdougherty left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@paoloredis
paoloredis merged commit 8e3476f into main Sep 23, 2026
97 of 98 checks passed
@paoloredis
paoloredis deleted the DOC-5845-copy-button-fix branch September 23, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants