Make WordPress Core

Opened 13 months ago

Closed 13 months ago

Last modified 12 months ago

#64128 closed defect (bug) (fixed)

html5_script_support variable is misleading

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

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
13 months ago

Not entirely sure of the purpose of the is_admin() check, but this logic may need to be changed to $html5_script_support = ! is_admin() && current_theme_supports( 'html5', 'script' );

Version 0, edited 13 months ago by jamieburchell (next)

#2 @westonruter
13 months ago

  • Owner set to westonruter
  • Status new → 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.


13 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
13 months ago

  • Component General → Script Loader
  • Version 6.8.3 → 5.7

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

#5 @SergeyBiryukov
13 months ago

  • Milestone Awaiting Review → 6.9

#6 @westonruter
13 months ago

  • Resolution → fixed
  • Status accepted → 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
12 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
12 months ago

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

Note: See TracTickets for help on using tickets.