Opened 9 years ago
Closed 9 years ago
#33470 closed defect (bug) (fixed)
wpdb class method get_table_from_query() malfunctions if table name contains a dash (-)
Reported by: | dustinbolton | Owned by: | pento |
---|---|---|---|
Milestone: | 4.3.1 | Priority: | normal |
Severity: | normal | Version: | 4.1.2 |
Component: | Database | Keywords: | has-patch commit fixed-major |
Focuses: | Cc: |
Description
The wpdb class in wp-db.php contains a method get_table_from_query() for getting the table name from a passed query. This method as it stands does not properly handle tables with a dash (-) in the table name, instead only returning the table name characters up the point of the dash. This appears to impact all query formats. Adding a dash (-) in three locations to the regular expressions for the table name capture corrects this issue.
Examples:
get_table_from_query( "SHOW COLUMNS FROM wp_posts" );
Returns: wp_posts
get_table_from_query( "SHOW COLUMNS FROM wp-posts" );
Returns: wp
Attachments (2)
Change History (16)
#2
@
9 years ago
So, here's the thing with this. According to the MySQL Docs, unquoted table names can only contain [0-9,a-z,A-Z$_]
(basic Latin letters, digits 0-9, dollar, underscore) and U+0080 .. U+FFFF
. A hyphen-minus is U+002D
, so according to the docs that needs to be quoted. WordPress uses unquoted table names in a lot of places, so I think it probably makes sense to only match accordingly.
Having said that, in my tests on all the MySQL versions I have handy, hyphens seem to work just fine in table names unquoted. It looks like a discrepancy in their docs and actual practice.
#3
@
9 years ago
- Milestone changed from Awaiting Review to 4.3.1
- Version changed from trunk to 4.1.2
Patch looks good. Could you add some unit tests, please?
This will also need to be backported to all branches.
#4
@
9 years ago
- Keywords needs-unit-tests removed
Patch works for me as well.
Attached a unit test for that case.
Some more different queries can be tested with dashed table names if you guys feel this is necessary.
#5
@
9 years ago
- Owner set to pento
- Resolution set to fixed
- Status changed from new to closed
In 33718:
wp-db.php diff of changes