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
This commit is contained in:
Boone Gorges 2015-02-06 02:02:23 +00:00
parent 5e4d135411
commit 7560f446f9
2 changed files with 12 additions and 2 deletions

View File

@ -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

View File

@ -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.