Make WordPress Core

Opened 6 months ago

Closed 6 months ago

Last modified 5 months ago

#64128 closed defect (bug) (fixed)

html5_script_support variable is misleading

Reported by: jamieburchell's profile jamieburchell Owned by: westonruter's profile westonruter
Milestone: 6.9 Priority: normal
Severity: normal Version: 5.7
Component: Script Loader Keywords: has-patch
Focuses: Cc:

Description

The $html5_script_support variable used in wp_sanitize_script_attributes() is misleading.

It reads that if the theme supports HTML5 script, use the longform attribute version foo="foo", otherwise only the attribute name. While technically the function returns the correct string due to its placement in the ternary operator, its meaning is backwards.

I believe that the variable should be:

$html5_script_support = is_admin() || current_theme_supports( 'html5', 'script' );

and used thus:

$attributes_string .= $html5_script_support ? ' ' . esc_attr( $attribute_name ) : sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_name ) );

Change History (8)

#1 @jamieburchell
6 months ago

Last edited 6 months ago by jamieburchell (previous) (diff)

#2 @westonruter
6 months ago

  • Owner set to westonruter
  • Status changed from new to accepted

@jamieburchell do you want to add a patch for your suggestion?

This ticket was mentioned in PR #10383 on WordPress/wordpress-develop by @jamieburchell.


6 months ago
#3

  • Keywords has-patch added

The $html5_script_support variable used in wp_sanitize_script_attributes() is misleading.

It reads that if the theme supports HTML5 script, use the longform attribute version foo="foo", otherwise only the attribute name. While technically the function returns the correct string due to its placement in the ternary operator, its meaning is backwards. This patch addresses this.

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

#4 @sabernhardt
6 months ago

  • Component changed from General to Script Loader
  • Version changed from 6.8.3 to 5.7

The $html5_script_support variable and the function go back to [50167].

#5 @SergeyBiryukov
6 months ago

  • Milestone changed from Awaiting Review to 6.9

#6 @westonruter
6 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 61052:

Script Loader: Fix logic inversion with $html5_script_support in wp_sanitize_script_attributes().

The value was actually whether HTML5 was not supported.

Follow-up to [50167].

Props jamieburchell, sabernhardt.
See #39941.
Fixes #64128.

#7 @desrosj
5 months ago

In 61196:

Build/Test Tools: Ensure all db WP-CLI commands work.

This ensures that the presence of a self-signed certificate from a MySQL/MariaDB container will not cause db WP-CLI commands run using env:cli in the local development environments to fail.

Follow up to [60735].

Props westonruter, mukesh27.
Fixes #64128. See #63876.

#8 @desrosj
5 months ago

Please ignore [61196]. This was meant for #64218,

Note: See TracTickets for help on using tickets.