Skip to content

Commit 1276a0f

Browse files
authored
Merge pull request #368 from KevinBatdorf/sanitize-copy-string
2 parents f260c27 + 3601e67 commit 1276a0f

File tree

6 files changed

+44
-12
lines changed

6 files changed

+44
-12
lines changed

.github/workflows/cypress-main.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,18 @@ jobs:
8484
with:
8585
name: '.wp-env.json'
8686
json: '{"core": "WordPress/WordPress#${{ env.branch }}","plugins":["."],"mappings":{"wp-content/plugins/prismatic": "https://downloads.wordpress.org/plugin/prismatic.zip"}}'
87-
- name: Start server
88-
run: |
89-
npx wp-env start
87+
88+
- name: Start wp-env
89+
uses: nick-fields/retry@v3
90+
with:
91+
timeout_minutes: 4
92+
max_attempts: 3
93+
retry_wait_seconds: 60
94+
shell: bash
95+
command: |
96+
npx wp-env start --update
9097
echo "WordPress version: `npx wp-env run cli core version`"
98+
9199
- name: Cypress run
92100
uses: cypress-io/github-action@v6
93101
with:

.github/workflows/cypress-push.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,18 @@ jobs:
6060
run: |
6161
npx eslint --max-warnings 0 .
6262
npm run build
63-
- name: Start server
64-
run: |
65-
npx wp-env start
63+
64+
- name: Start wp-env
65+
uses: nick-fields/retry@v3
66+
with:
67+
timeout_minutes: 4
68+
max_attempts: 3
69+
retry_wait_seconds: 60
70+
shell: bash
71+
command: |
72+
npx wp-env start --update
6673
echo "WordPress version: `npx wp-env run cli core version`"
74+
6775
- name: Cypress run
6876
uses: cypress-io/github-action@v6
6977
with:

code-block-pro.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Author URI: https://code-block-pro.com/?utm_campaign=plugin&utm_source=author-uri
99
* Requires at least: 6.0
1010
* Requires PHP: 7.0
11-
* Version: 1.27.2
11+
* Version: 1.27.3
1212
* License: GPL-2.0-or-later
1313
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
1414
* Text Domain: code-block-pro

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Contributors: kbat82, dcooney, a169kai
33
Tags: block, code, syntax, highlighter, php
44
Tested up to: 6.8
5-
Stable tag: 1.27.2
5+
Stable tag: 1.27.3
66
License: GPL-2.0-or-later
77
License URI: https://www.gnu.org/licenses/gpl-2.0.html
88

@@ -313,6 +313,9 @@ Themes are rendered inside the editor as you type or make changes, so the code b
313313

314314
== Changelog ==
315315

316+
= 1.27.3 - 2025-05-15 =
317+
- Prevents smart quotes, typographic dashes, and other non-ASCII characters from affecting copied code snippets.
318+
316319
= 1.27.2 - 2025-05-15 =
317320
- Refactors the copy button to use a textarea for copying
318321
- Removed the WP outline style on the copy button and pre (now only when tab focused)

src/editor/components/buttons/copy/CopyButton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ export const CopyButton = ({ attributes }: { attributes: Attributes }) => {
7070
<textarea
7171
className="code-block-pro-copy-button-textarea"
7272
aria-hidden="true"
73-
readOnly>
74-
{codeToCopy}
75-
</textarea>
73+
readOnly
74+
value={codeToCopy}
75+
/>
7676
) : null}
7777
<Component text={copyButtonString} />
7878
</span>

src/front/front.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ import copy from 'copy-to-clipboard';
22

33
const containerClass = '.wp-block-kevinbatdorf-code-block-pro';
44

5+
const sanitize = (str) =>
6+
str
7+
.replace(/[\u2018\u2019]/g, "'") // single quotes
8+
.replace(/[\u201C\u201D]/g, '"') // double quotes
9+
.replace(/[\u2013\u2014]/g, '-') // en/em dash
10+
.replace(/\u2026/g, '...') // ellipsis
11+
.replace(/[\u2039\u203A\u00AB\u00BB]/g, (c) =>
12+
c === '‹' || c === '«' ? '<' : '>',
13+
)
14+
.replace(/\u00A0/g, ' '); // non-breaking space
15+
516
const handleCopyButton = () => {
617
const buttons = Array.from(
718
document.querySelectorAll(
@@ -22,7 +33,9 @@ const handleCopyButton = () => {
2233
const code = b?.dataset?.encoded
2334
? decodeURIComponent(decodeURIComponent(source))
2435
: source;
25-
const content = window.cbpCopyOverride?.(code, button) ?? code;
36+
const content = sanitize(
37+
window.cbpCopyOverride?.(code, button) ?? code,
38+
);
2639
copy(content ?? '', {
2740
format: 'text/plain',
2841
onCopy: (code) => {

0 commit comments

Comments
 (0)