Make WordPress Core

Opened 23 months ago

Closed 23 months ago

Last modified 22 months ago

#56338 closed defect (bug) (fixed)

`taxonomy_exists()` does not guard against non-string arguments.

Reported by: costdev's profile costdev Owned by: audrasjb's profile audrasjb
Milestone: 6.1 Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords: php8 has-patch has-unit-tests commit
Focuses: Cc:


Follow-up to #56336.

While testing the issue reported by @dd32, I came across a similar warning/error. This can be produced, for example, when using Yoast SEO for sitemaps.

Warning: Illegal offset type in isset or empty in src/wp-includes/taxonomy.php on line 340

Tested and verified by @peterwilsoncc

Adding an is_string( $taxonomy ) check to the condition in taxonomy_exists resolves the issue. The $taxonomy argument is documented as a string.

Change History (9)

This ticket was mentioned in PR #3066 on WordPress/wordpress-develop by costdev.

23 months ago

  • Keywords has-patch has-unit-tests added

#2 @costdev
23 months ago

  • Keywords commit added
  • Version set to 3.0

Introduced in [35718] in WordPress 3.0, formerly is_taxonomy() in WordPress 2.3.

PR 3066 is ready for review by a committer.

mukeshpanchal27 commented on PR #3066:

23 months ago

@costdev Can you please add test coverage for the special characters?

costdev commented on PR #3066:

23 months ago

@costdev Can you please add test coverage for the special characters?

Hi @mukeshpanchal27, I'm not sure what you mean. Which special characters will trigger an illegal offset warning/error?

#5 @mukesh27
23 months ago

Hi there,

PR looks good to me.

#6 @audrasjb
23 months ago

  • Owner changed from costdev to audrasjb
  • Status changed from assigned to accepted

Looks good to go. Self-assigning for commit.

#7 @audrasjb
23 months ago

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

In 53869:

Taxonomy: Prevent non string taxonomy names generating warnings or errors.

This changeset adds an is_string( $taxonomy ) check to the condition in taxonomy_exists(), to ensure false is returned when the $taxonomy is not a string.

Follow-up to [35718].

Props costdev, peterwilsoncc, mukesh27.
Fixes #56338.
See #56336.

#9 @SergeyBiryukov
22 months ago

In 54052:

Tests: Correct the @covers tag syntax in a taxonomy_exists() test with non-string taxonomy.

This addresses a notice when generating the code coverage report:

"@covers :taxonomy_exists" is invalid

Follow-up to [53869].

See #56338, #55652.

Note: See TracTickets for help on using tickets.