WordPress.org

Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#9670 closed defect (bug) (fixed)

wp_category_checklist may output incorrect results

Reported by: hailin Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

wp_category_checklist has a loop through $categories, it assumes the index begins with 0, and auto-increments. Most $categories will be that case. However, this is a shaky assumption. PHP doesn't guarantee that. I've seem its index begin with 2, for example. and it may not be consecutive.

This will cause the function to output wrong data set sometimes.
The idea is similar to #9661

The fix is to get array_keys first, then loop through the keys. I've verified that the following patch works correctly.

Attachments (1)

9670_checklist.diff (972 bytes) - added by hailin 12 years ago.
patch

Download all attachments as: .zip

Change History (6)

@hailin
12 years ago

patch

#1 @hailin
12 years ago

This is a safe fix too, as the logic is obvious.
However when the problem occurs, it could be very difficult to track it down.

#2 @hailin
12 years ago

the patch is taken against today's WP trunk.

#3 @ryan
12 years ago

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

(In [11130]) Allow for non-contiguous array indices. Props hailin. fixes #9670

#4 @Denis-de-Bernardy
12 years ago

Ack. I had written a patch in that very same area that fixes a bug in another ticket, related to category selector weirdness.

@ryan: If you find it before I do, please bump it with a "patch is stale" or something, so I get an email.

#5 @Denis-de-Bernardy
12 years ago

  • Milestone changed from Unassigned to 2.8
Note: See TracTickets for help on using tickets.