Skip to content

Document the known bugs in the deprecated duotone functions - #68397

Merged
westonruter merged 4 commits into
WordPress:trunkfrom
justlevine:fix/strict-comparison-gutenberg_tinycolor_bound01
Oct 25, 2026
Merged

westonruter merged 4 commits into
WordPress:trunkfrom
justlevine:fix/strict-comparison-gutenberg_tinycolor_bound01

Conversation

@justlevine

Copy link
Copy Markdown
Contributor

What?

This PR fixes an issue in gutenberg_tinycolor_bound01() where an int is strict-compared to a float, resulting in an always-false comparison.

Why?

While this issue was surfaced by PHPStan (via #66693) it can be remediated independently as part of #66598

How?

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

Before After

@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core, Gutenberg Plugin.
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@justlevine
justlevine force-pushed the fix/strict-comparison-gutenberg_tinycolor_bound01 branch from 5986eb3 to 80c5ffa Compare April 18, 2025 22:58
westonruter and others added 3 commits October 24, 2026 21:53
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Revert the strict comparison change in `gutenberg_tinycolor_bound01()`
and instead ignore the PHPStan errors in the deprecated duotone
functions, with a reason for each. Fixing the comparison alone does not
make the function behave as in TinyColor: it would turn '1.0' into
'100%', but the percentage check further down never matches, because
`$n` has already been cast to a number by then. So with a max of 255,
'1.0' would go from 0.0039 to 0.3922, rather than to 1.

Since these functions have been deprecated since 6.3.0 and are only
called by each other, the bugs are documented where PHPStan reports
them rather than fixed:

* `gutenberg_tinycolor_bound01()`: '1.0' is never treated as 100%, and
  percentages are never converted.
* `gutenberg_tinycolor_hsl_to_rgb()`: the achromatic branch never runs,
  though the general formula yields the same gray.
* `gutenberg_tinycolor_string_to_rgb()`: an unrecognized color string
  returns null.
* `gutenberg_render_duotone_support()`: the required `$wp_block` argument
  is not passed, so it throws an `ArgumentCountError`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`gutenberg_render_duotone_support()` called
`WP_Duotone_Gutenberg::render_duotone_support()` without its required
`$wp_block` argument, so it threw an `ArgumentCountError`. Core fixed its
`wp_render_duotone_support()` in r56226 by creating a `WP_Block` from the
parsed block, so do the same here instead of ignoring the PHPStan error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@westonruter westonruter added No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Code Quality Issues or PRs that relate to code quality labels Oct 25, 2026
@westonruter westonruter changed the title fix: incorrect int to float strict comparison in gutenberg_tinycolor_bound01() Document the known bugs in the deprecated duotone functions Oct 25, 2026
@westonruter

Copy link
Copy Markdown
Member

🤖 Comment by Claude Opus 5.5

trunk was merged in, and the five PHPStan level 5 errors in the deprecated duotone functions are now handled as follows: 065bd15 replaces the 1.0 === fix with @phpstan-ignore comments, each with a reason, on four of them, and bd7d437 fixes the fifth by syncing with core.

The comparison fix alone does not make gutenberg_tinycolor_bound01() behave as in TinyColor. It turns '1.0' into '100%', but the percentage check further down never matches, since $n has already been cast to a number by then (PHPStan reports that check as always false too). Running the function before and after the fix:

Input Before After TinyColor
'1.0', max 255 0.0039 0.3922 1
'1.0', max 100 0.01 1 1
'100%', max 255 0.3922 0.3922 1

A faithful port would also need the percentage to be detected before the cast, and fmod() instead of the integer %. Since these functions have been deprecated since 6.3.0 and are only called by each other, the bugs are documented where PHPStan reports them instead:

  • gutenberg_tinycolor_bound01(): '1.0' is never treated as 100%, and percentages are never converted.
  • gutenberg_tinycolor_hsl_to_rgb(): the achromatic branch never runs, though the general formula yields the same gray.
  • gutenberg_tinycolor_string_to_rgb(): an unrecognized color string returns null.

The fifth, gutenberg_render_duotone_support(), did not pass the required $wp_block argument to WP_Duotone_Gutenberg::render_duotone_support(), so it threw an ArgumentCountError. Core already fixed wp_render_duotone_support() in r56226 by creating a WP_Block from the parsed block, so the same is now done here.

Core's deprecated copies of the other three functions in wp-includes/deprecated.php have the same bugs, but core's PHPStan configuration excludes that file, so the No Core Sync Required label was added.

@github-actions

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: justlevine <justlevine@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@westonruter
westonruter merged commit cc15bb5 into WordPress:trunk Oct 25, 2026
79 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Oct 25, 2026
@ingeniumed ingeniumed added [Feature] Colors Color management [Type] Bug An existing feature does not function as intended and removed [Type] Code Quality Issues or PRs that relate to code quality labels Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Colors Color management No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants