From 4afafbde250e0861be350838c05dbe5d2ac98ad2 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 2 Sep 2016 00:18:49 +0000 Subject: [PATCH] Database: Find the correct table names in `DELETE` queries with table aliases Previously, `wpdb::get_table_from_query()` would not find the correct table name in the query `DELETE a FROM table a`, due to not recognising the table alias immediately after the `DELETE` as correct syntax. Fixes #37660. git-svn-id: https://develop.svn.wordpress.org/trunk@38507 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/wp-db.php | 2 +- tests/phpunit/tests/db.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php index 02577b910d..f4f0826897 100644 --- a/src/wp-includes/wp-db.php +++ b/src/wp-includes/wp-db.php @@ -3029,7 +3029,7 @@ class wpdb { . '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?' . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?' . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?' - . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?' + . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:.+?FROM)?' . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) { return str_replace( '`', '', $maybe[1] ); } diff --git a/tests/phpunit/tests/db.php b/tests/phpunit/tests/db.php index a876869346..7cff637149 100644 --- a/tests/phpunit/tests/db.php +++ b/tests/phpunit/tests/db.php @@ -562,6 +562,8 @@ class Tests_DB extends WP_UnitTestCase { "DELETE QUICK $table", "DELETE IGNORE $table", "DELETE LOW_PRIORITY FROM $table", + "DELETE a FROM $table a", + "DELETE `a` FROM $table a", // STATUS "SHOW TABLE STATUS LIKE '$table'",