From 7560f446f93c5aafe76b1a9e2b37b8d0e72a2c4f Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 6 Feb 2015 02:02:23 +0000 Subject: [PATCH] Use field-specific sanitization in `WP_Tax_Query::transform_query()`. When terms are entered into the database, term fields are sanitized with `sanitize_term_field()`. To ensure that the `SELECT ... WHERE` queries in `WP_Tax_Query::transform_query()` are not broken by overzealous sanitization, `sanitize_term_field()` should be used in that case as well. This fixes a bug where a tax_query using 'field=name' would fail if the 'terms' parameter contained characters (like spaces) that were improperly removed by `sanitize_title_for_query()`. Fixes #27810. Built from https://develop.svn.wordpress.org/trunk@31346 git-svn-id: http://core.svn.wordpress.org/trunk@31327 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 12 +++++++++++- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index ec398b44aa..6deb0030d4 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1226,7 +1226,17 @@ class WP_Tax_Query { switch ( $query['field'] ) { case 'slug': case 'name': - $terms = "'" . implode( "','", array_map( 'sanitize_title_for_query', $query['terms'] ) ) . "'"; + foreach ( $query['terms'] as &$term ) { + /* + * 0 is the $term_id parameter. We don't have a term ID yet, but it doesn't + * matter because `sanitize_term_field()` ignores the $term_id param when the + * context is 'db'. + */ + $term = "'" . sanitize_term_field( $query['field'], $term, 0, $query['taxonomy'], 'db' ) . "'"; + } + + $terms = implode( ",", $query['terms'] ); + $terms = $wpdb->get_col( " SELECT $wpdb->term_taxonomy.$resulting_field FROM $wpdb->term_taxonomy diff --git a/wp-includes/version.php b/wp-includes/version.php index 0326f314ab..a1068ccb59 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31345'; +$wp_version = '4.2-alpha-31346'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.