Problem/Motivation
The PostgreSQL driver overrides the escapeField
, escapeAlias
and escapeTable
methods to deal with case sensitive names and reserved keywords.
Leaving aside the fact that this code has a serious lack of factorization, the table escape introduces a major bug. Currently, the escapeTable method escapes the entire table name as it has been given. The thing is that this table name can include the database and the schema names too.
echo \Drupal::database()->escapeTable('myDb.public.node');
Expected: "myDb".public.node
Current: "myDb.public.node"
Proposed resolution
Factorize for sanity
Explode the table name and handle each part separately
Remaining tasks
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Create a patch | Instructions | Done | |
Add automated tests | Instructions | Done | |
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards | Instructions |
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#12 | drupal_pgsql_escape_issue-2726747-12.patch | 3.66 KB | DuaelFr |
#12 | interdiff.2726747.7.12.txt | 973 bytes | DuaelFr |
#7 | drupal_pgsql_escape_issue-2726747-7.patch | 3.42 KB | DuaelFr |
#7 | drupal_pgsql_escape_issue-2726747-7-tests-only.patch | 718 bytes | DuaelFr |
#7 | interdiff.2726747.3.7.txt | 1.63 KB | DuaelFr |
Comments
Comment #2
DuaelFrComment #3
DuaelFrI just added a tiny test to demonstrate the issue.
Comment #6
Crell CreditAttribution: Crell at Platform.sh commentedExtra space at the end of this line, according to Dreditor.
There's no need to name methods with a _ prefix if you're on PHP 5.0 or later. :-)
I don't know why the MySQL testbot is affected by this patch. That seems... odd. Other than the above the code looks reasonable on visual inspection.
Comment #7
DuaelFrThanks @Crell for your review.
As I don't really understand why tests failed while they are passing on my local environment, I just updated my patch with your suggestions.
Let's see if the testbot is happier.
Comment #9
DuaelFrThe testbot seems quite unstable theses days. Re-requeueing the test.
Comment #10
daffie CreditAttribution: daffie commentedThe remarks of @Crell in comment #6 are all fixed.
There is a test added to make sure that the problem is fixed.
It all looks good to me.
Comment #11
alexpottI think we should add test coverage of the database.schema.table pattern... since the pattern tested here only has one dot.
Comment #12
DuaelFrDone :)
Comment #13
bzrudi71 CreditAttribution: bzrudi71 commentedLooks good to me and we have PG pass too, back to RTBC. Thanks @DuaelFr
Comment #14
alexpottCommitted 9233946 and pushed to 8.2.x. Thanks!
Only committing to 8.2.x because of the addition of the protected method.