Make WordPress Core


Ignore:
Timestamp:
09/29/2023 07:45:53 PM (5 months ago)
Author:
westonruter
Message:

Script Loader: Harden removal of script tag wrappers.

  • Add wp_remove_surrounding_empty_script_tags() to more precisely remove script tag wrappers and warn when doing it wrong.
  • Add clarifying comments for XML escaping logic in wp_get_inline_script_tag().
  • Leverage WP_HTML_Tag_Processor in test_remove_frameless_preview_messenger_channel.
  • Reuse assertEqualMarkup in test_blocking_dependent_with_delayed_dependency.
  • Normalize whitespace in parse_markup_fragment for assertEqualMarkup.

Follow-up to [56687].
Props dmsnell, westonruter, flixos90.
See #58664.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r56687 r56748  
    261261        wp_enqueue_script( 'dependent-script-a3', '/dependent-script-a3.js', array( 'main-script-a3' ), null );
    262262        $output   = get_echo( 'wp_print_scripts' );
    263         $expected = str_replace( "'", '"', "<script type='text/javascript' src='/main-script-a3.js' id='main-script-a3-js' data-wp-strategy='{$strategy}'></script>" );
    264         $this->assertStringContainsString( $expected, $output, 'Blocking dependents must force delayed dependencies to become blocking.' );
     263        $expected = <<<JS
     264            <script type='text/javascript' src='/main-script-a3.js' id='main-script-a3-js' data-wp-strategy='{$strategy}'></script>
     265            <script id="dependent-script-a3-js" src="/dependent-script-a3.js" type="text/javascript"></script>
     266JS;
     267        $this->assertEqualMarkup( $expected, $output, 'Blocking dependents must force delayed dependencies to become blocking.' );
    265268    }
    266269
     
    29983001        }
    29993002
     3003        // Normalize other whitespace nodes.
     3004        $xpath = new DOMXPath( $dom );
     3005        foreach ( $xpath->query( '//text()' ) as $node ) {
     3006            /** @var DOMText $node */
     3007            if ( preg_match( '/^\s+$/', $node->nodeValue ) ) {
     3008                $node->nodeValue = ' ';
     3009            }
     3010        }
     3011
    30003012        return $dom;
    30013013    }
Note: See TracChangeset for help on using the changeset viewer.