Skip to content

Commit fa7d8d3

Browse files
committed
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 WordPress#12008. Follow-up to r47572, r50161. Props masteradhoc, vivekawsm, westonruter, sruthi89, sumitbagthariya16. Fixes #58969. git-svn-id: https://develop.svn.wordpress.org/trunk@62663 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f04cb62 commit fa7d8d3

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/js/_enqueues/admin/privacy-tools.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,10 @@ jQuery( function( $ ) {
296296
range = document.createRange();
297297
$parent.addClass( 'hide-privacy-policy-tutorial' );
298298

299-
// Copy action.
300-
range.selectNodeContents( $parent[0] );
299+
// Copy action. Select only the dedicated copy-content wrapper
300+
// so the actions toolbar (which contains the "Copied!" notice
301+
// and button label) is never part of the selection - see #58969.
302+
range.selectNodeContents( $parent.find( '.privacy-text-copy-content' )[0] );
301303
window.getSelection().addRange( range );
302304
document.execCommand( 'copy' );
303305

src/wp-admin/includes/class-wp-privacy-policy-content.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,12 @@ public static function privacy_policy_guide() {
420420
</button>
421421
</h4>
422422
<div id="privacy-settings-accordion-block-<?php echo $i; ?>" class="privacy-settings-accordion-panel privacy-text-box-body" hidden="hidden">
423-
<?php
424-
echo $removed;
425-
echo $section['policy_text'];
426-
?>
423+
<div class="privacy-text-copy-content">
424+
<?php
425+
echo $removed;
426+
echo $section['policy_text'];
427+
?>
428+
</div>
427429
<?php if ( empty( $section['removed'] ) ) : ?>
428430
<div class="privacy-settings-accordion-actions">
429431
<span class="success" aria-hidden="true"><?php _e( 'Copied!' ); ?></span>

0 commit comments

Comments
 (0)