From 7711b726397991caa4b0174b7251453597fb3cab Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Tue, 14 Jul 2015 10:18:57 +0000 Subject: [PATCH] WPDB: When extracting the table name from a query, we had a 1000 character limit on the SQL string that would be searched. This was a hangover from when the code was imported from HyperDB, and isn't appropriate for Core, where a wider range of queries are likely to be run. Fixes #32763 git-svn-id: https://develop.svn.wordpress.org/trunk@33259 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/wp-db.php | 7 ++----- tests/phpunit/tests/db.php | 5 +++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php index 2f6d4f484c..cbf2abf77f 100644 --- a/src/wp-includes/wp-db.php +++ b/src/wp-includes/wp-db.php @@ -2868,11 +2868,8 @@ class wpdb { // Allow (select...) union [...] style queries. Use the first query's table name. $query = ltrim( $query, "\r\n\t (" ); - /* - * Strip everything between parentheses except nested selects and use only 1,000 - * chars of the query. - */ - $query = preg_replace( '/\((?!\s*select)[^(]*?\)/is', '()', substr( $query, 0, 1000 ) ); + // Strip everything between parentheses except nested selects. + $query = preg_replace( '/\((?!\s*select)[^(]*?\)/is', '()', $query ); // Quickly match most common queries. if ( preg_match( '/^\s*(?:' diff --git a/tests/phpunit/tests/db.php b/tests/phpunit/tests/db.php index a8524aa2cb..9a6be9f30b 100644 --- a/tests/phpunit/tests/db.php +++ b/tests/phpunit/tests/db.php @@ -533,6 +533,8 @@ class Tests_DB extends WP_UnitTestCase { "SELECT * FROM $table", "SELECT * FROM `$table`", + "SELECT * FROM (SELECT * FROM $table) as subquery", + "INSERT $table", "INSERT IGNORE $table", "INSERT IGNORE INTO $table", @@ -627,6 +629,9 @@ class Tests_DB extends WP_UnitTestCase { "SHOW FULL COLUMNS FROM $table", "SHOW CREATE TABLE $table", "SHOW INDEX FROM $table", + + // @ticket 32763 + "SELECT " . str_repeat( 'a', 10000 ) . " FROM (SELECT * FROM $table) as subquery", ); $querycount = count( $queries );