Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#9670 closed defect (bug) (fixed)

wp_category_checklist may output incorrect results

Reported by: hailin Owned by: anonymous
Priority: normal Milestone: 2.8
Component: General Version:
Severity: normal Keywords:
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 4 years ago.
patch

Download all attachments as: .zip

Change History (6)

hailin4 years ago

patch

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.

the patch is taken against today's WP trunk.

comment:3   ryan4 years ago

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

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

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.

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