Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#29467 closed defect (bug) (fixed)

is_object_in_term() return true If the term name begins with a number

Reported by: nobinobi's profile nobinobi Owned by: boonebgorges's profile boonebgorges
Milestone: 4.1 Priority: normal
Severity: normal Version: 2.7
Component: Taxonomy Keywords:
Focuses: Cc:

Description

If the term name begins with a number Might return true even if the post not belongs to a taxonomy term

this code return true

$object_term->term_id = 10;
$strs = array("10_term_name");

if ( in_array( $object_term->term_id, $strs ) ) return true;

change to

if ( in_array( $object_term->term_id, $strs , true ) ) return true;

Attachments (2)

taxonomy.diff (664 bytes) - added by nobinobi 10 years ago.
taxonomy-unittests.diff (891 bytes) - added by realloc 10 years ago.
Unit test for the ticket #29467

Download all attachments as: .zip

Change History (11)

@nobinobi
10 years ago

#2 @johnbillion
10 years ago

  • Version changed from trunk to 2.7

#3 @boonebgorges
10 years ago

  • Keywords needs-unit-tests added

@realloc
10 years ago

Unit test for the ticket #29467

#4 @realloc
10 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

The function filters the integers and compares them before the mentioned line will be executed.

#5 @DrewAPicture
10 years ago

  • Keywords has-patch needs-testing added
  • Resolution worksforme deleted
  • Status changed from closed to reopened

We only use worksforme when we can't reproduce a bug, it doesn't have anything to do with the patch/unit tests workflow. Reopening :)

#6 @realloc
10 years ago

@DrewAPicture Oh, sorry for that. Seems I should read the contributors handbook more accurately. ;)

Anyway I could not reproduce this problem.

#7 @boonebgorges
10 years ago

  • Keywords needs-unit-tests has-patch needs-testing removed
  • Milestone changed from Awaiting Review to 4.1
  • Owner set to boonebgorges
  • Status changed from reopened to accepted

nobinobi - Thanks for the report and the suggested fix.

realloc - Thanks for writing up the unit test. It's almost right: the issue that nobinobi only arises if you concatenate a term string *that begins with the ID of a term that the post belongs to*, not the ID of the post itself.

#8 @boonebgorges
10 years ago

In 30204:

Add some unit tests for is_object_in_term().

These tests check a number of the ways that different kinds of values for
$terms (integers that match term_id, strings that match term_id or name or
slug) are handled.

See #29467.

#9 @boonebgorges
10 years ago

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

In 30205:

In in_object_in_term(), only check numeric string values against term_id.

The previous in_array() check was playing too loose with mixed types, such
that a string like '10_term_name' would incorrectly match a term_id 10.

Props nobinobi, realloc.
Fixes #29467.

Note: See TracTickets for help on using tickets.