Make WordPress Core

Opened 3 years ago

Closed 3 months ago

#58969 closed defect (bug) (fixed)

Privacy setting > The ''Copied'' text also shows, When double-clicking on the 'Copy suggested policy text to clipboard' option,

Reported by: vivekawsm Owned by: masteradhoc
Priority: normal Milestone: 7.1
Component: Privacy Version: 6.3
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

When double clicked the Copy suggested policy text to clipboard and paste it to the notes the copied text is also showing ( Only when double clicking )

Environment

  • WordPress: 6.3-RC3-56344
  • PHP: 7.4.33
  • Server: TasteWP-S4 Official/3.0.0
  • Database: mysqli (Server: 8.0.32-0ubuntu0.20.04.2 / Client: mysqlnd 7.4.33)
  • Browser: Firefox 116.0 (Windows 10/11)
  • Theme: Twenty Twenty-Three 1.2
  • MU-Plugins: None activated
  • Plugins:
    • WordPress Beta Tester 3.5.2

Steps to Reproduce

  1. Open the wordpress 'policies' section
  2. Double Click on the 'Copy suggested policy text to clipboard 'option
  3. Paste the policy on the notepad or notes
  4. Copied text is showing

Expected Results

When you double-click on the 'Copy suggested policy text to clipboard' option, the 'Copied' text should not be displayed.

Actual Results

When you double-click the 'Copy suggested policy text to clipboard' option, the 'Copied' text is also displayed.

Attachments (2)

Screenshot 2023-08-03 171058.png​ (223.4 KB ) - added by vivekawsm 3 years ago.
image_2023_08_03T12_12_22_680Z.png​ (207.9 KB ) - added by vivekawsm 3 years ago.

Download all attachments as: .zip

Change History (10)

#1 @sruthi89
3 years ago

  • Focuses performance added; privacy removed
  • Keywords dev-feedback added

Hi vivekawsm,

I could reproduce the issue with the exact steps as specified.

​https://www.loom.com/share/183aa9790a3e46ecaf7438b5bfcfaf5f?sid=59ddb997-2f94-4708-8c06-da7a50a96c89

#2 @sruthi89
3 years ago

  • Focuses performance removed
  • Keywords dev-feedback removed

#3 @sumitbagthariya16
3 years ago

I've been able to reproduce the same issue consistently.

This ticket was mentioned in ​Slack in #core by priethor. ​View the logs.


3 years ago

This ticket was mentioned in ​PR #12008 on ​WordPress/wordpress-develop by ​@masteradhoc.


5 months ago
#5

  • Keywords has-patch added

When a user double-clicks the "Copy suggested policy text to clipboard" button, the "Copied!" notice text was included in the clipboard contents when pasted.

The root cause: document.execCommand('copy') copies all text content within the selected range, including text that is merely visually hidden via CSS. The .success ("Copied!") span and the button label both live inside .privacy-settings-accordion-actions, which sits inside the panel being selected — so their text was always part of the copy, becoming noticeable on double-click when the notice is visibly rendered.

The fix adds .privacy-settings-accordion-actions to the existing hide-privacy-policy-tutorial class before selectNodeContents runs, then removes it immediately after — the same mechanism already used to exclude tutorial paragraphs from the copied content.

Trac ticket: https://core.trac.wordpress.org/ticket/58969

## Use of AI Tools

AI assistance: Yes
Tool(s): Claude (claude.ai)
Model(s): Claude Sonnet 4.6
Used for: Debugging and identifying the root cause; the fix was reviewed, tested, and approved by me.

#6 @masteradhoc
4 months ago

  • Milestone Awaiting Review → 7.1
  • Owner set to masteradhoc
  • Status new → assigned

​@masteradhoc commented on ​PR #12008:


3 months ago
#7

Thank you very much for the review @westonruter, always appreciated.
I took your suggestion and reworked the solution to wrap the content once more and only copy this one - regarding of the added "Copied!".

Tested locally and over ​https://playground.wordpress.net/?core-pr=12008 both work perfectly.
Let me know if anything more is needed.

#8 @westonruter
3 months ago

  • Resolution → fixed
  • Status assigned → closed

In 62663:

Privacy: Exclude the "Copied!" notice from copied policy text.

The "Copy suggested policy text to clipboard" action selected the entire accordion panel, whose contents include the actions toolbar holding the "Copied!" confirmation notice and the button label. Running document.execCommand( 'copy' ) copies every text node in the selection, including ones hidden with CSS. So double-clicking the button, which renders the notice, leaked "Copied!" into the clipboard. Wrap the suggested policy text in a dedicated .privacy-text-copy-content container and select only that node, so the actions toolbar is never part of the copied range.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/12008.
Follow-up to r47572, r50161.

Props masteradhoc, vivekawsm, westonruter, sruthi89, sumitbagthariya16.
Fixes #58969.

Note: See TracTickets for help on using tickets.