Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#19952 closed defect (bug) (fixed)

Passing an empty array into wp_get_object_terms results in an invalid query

Reported by: batmoo's profile batmoo Owned by: duck_'s profile duck_
Milestone: 3.4 Priority: normal
Severity: normal Version: 3.3.1
Component: General Keywords: has-patch
Focuses: Cc:

Description

Doing something like this:

wp_get_object_terms( array(), 'category' );

...results in this:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY t.name ASC' at line 1]
SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN () ORDER BY t.name ASC

wp_get_object_terms should catch and prevent this.

Attachments (1)

19952.diff (451 bytes) - added by batmoo 14 years ago.

Download all attachments as: .zip

Change History (4)

@batmoo
14 years ago

#1 @batmoo
14 years ago

  • Keywords has-patch added

Attached patch checks for empty ids and taxonomies passed in and returns an empty array.

#2 @ryan
14 years ago

  • Milestone changed from Awaiting Review to 3.4

#3 @duck_
14 years ago

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

In [19975]:

Stop invalid SQL syntax by bailing from wp_get_object_terms() if $object_ids or $taxonomies is empty. Props batmoo. Fixes #19952.

Note: See TracTickets for help on using tickets.