Make WordPress Core

Opened 8 months ago

Closed 3 months ago

Last modified 3 months ago

#59496 closed defect (bug) (fixed)

Duotone undefined index/array key warning

Reported by: jacobcassidy's profile jacobcassidy Owned by: swissspidy's profile swissspidy
Milestone: 6.5 Priority: normal
Severity: normal Version: 6.3
Component: Editor Keywords: has-patch has-testing-info has-unit-tests
Focuses: Cc:

Description

When using a hsl() value to create duotones in theme.json, such as:

"duotone": [
  {
    "colors": ["hsl(0, 0%, 35%)", "hsl(0, 0%, 95%)"],
    "slug": "gray-scale",
    "name": "Gray Scale"
  }
]

PHP will throw a warning about an undefined index (in PHP 7.4) or undefined array key (in PHP 8+) when a block uses that duotone on a page.

The exact warning is:
"PHP Warning: Undefined array key "" in ../wp-includes/class-wp-duotone.php on line 212"

Change History (7)

This ticket was mentioned in PR #5351 on WordPress/wordpress-develop by jacobcassidy.


8 months ago
#1

Added an if statement with isset() to confirm that $angle_units[ $unit ] is valid before assigning it to $factor to avoid outputting a PHP warning.

#2 @hellofromTonya
7 months ago

  • Component changed from General to Editor
  • Keywords has-testing-info needs-unit-tests added
  • Milestone changed from Awaiting Review to 6.5
  • Version changed from trunk to 6.3

Hello @jacobcassidy,

Welcome to WordPress Core's Trac :) Thank you for reporting this issue.

The code in question was introduced in 6.3.0 via #58555 / [56101]. Thus, I updated the Version to reflect when it was introduced.

Moving this ticket into 6.5. Adding needs-unit-tests for the patch, as PHPUnit tests can help to validate the issue and code changes and prevent future regressions.

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


3 months ago
#3

  • Keywords has-unit-tests added; needs-unit-tests removed

#4 @Rahmohn
3 months ago

Hello @jacobcassidy and @hellofromTonya,

I did a small refactoring in the code change suggested by @jacobcassidy. Also, I added a unit test.

#5 @swissspidy
3 months ago

  • Owner set to swissspidy
  • Resolution set to fixed
  • Status changed from new to closed

In 57652:

Editor: Prevent PHP warning when parsing duotone hue values.

Props jacobcassidy, rahmohn, mukesh27.
Fixes #59496.

Note: See TracTickets for help on using tickets.