Make WordPress Core

Changeset 62663


Ignore:
Timestamp:
07/08/2026 03:18:16 AM (4 months ago)
Author:
westonruter
Message:

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/privacy-tools.js

    r58455 r62663  
    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' );
  • trunk/src/wp-admin/includes/class-wp-privacy-policy-content.php

    r62661 r62663  
    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">
Note: See TracChangeset for help on using the changeset viewer.