[wp-trac] [WordPress Trac] #37660: RegEx in wpdb::get_table_from_query( $q ) in wp-db.php returns table_alias='a' rather than table_name=wp_999_options

WordPress Trac noreply at wordpress.org
Mon Aug 15 01:00:49 UTC 2016


#37660: RegEx in wpdb::get_table_from_query( $q ) in wp-db.php returns
table_alias='a' rather than table_name=wp_999_options
------------------------------------------+-----------------------
 Reporter:  webp                          |       Owner:  pento
     Type:  defect (bug)                  |      Status:  accepted
 Priority:  normal                        |   Milestone:  4.7
Component:  Database                      |     Version:  4.1.2
 Severity:  normal                        |  Resolution:
 Keywords:  needs-unit-tests needs-patch  |     Focuses:
------------------------------------------+-----------------------
Changes (by pento):

 * keywords:   => needs-unit-tests needs-patch
 * owner:   => pento
 * version:  trunk => 4.1.2
 * status:  new => accepted
 * milestone:  Awaiting Review => 4.7


Comment:

 Thank you for the detailed investigation and bug report, @webp!

 You are correct, this is definitely a bug, even more so that it affects a
 query in Core.

 I think the fix will be to replace the current `(?:\s+FROM)` part of the
 match with `(?:.+?FROM)` - similar to your suggestion, but the additional
 `?` should make it a non-greedy match, stopping at the first `FROM`. This
 will need testing, of course. :-)

 The obvious shortcoming of `wpdb::get_table_from_query()` is that it only
 returns the first table in a multi-table query - as was the case with the
 method's HyperDB origins, it assumes that you're only querying tables on
 the same server. I'm fine with this behaviour continuing for this
 variation of `DELETE` syntax.

 I had a quick look at the other queries that
 `wpdb::get_table_from_query()` matches - I don't think there are any
 affected by similar bugs. Extra eyes are always welcome, of course, please
 point out if you notice any others!

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37660#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list