Skip to content

Double a quote character inside an identifier instead of replacing it - #250

Merged
simon-mundy merged 9 commits into
php-db:0.6.xfrom
simon-mundy:fix/quote-identifier-escape
Nov 17, 2026
Merged

simon-mundy merged 9 commits into
php-db:0.6.xfrom
simon-mundy:fix/quote-identifier-escape

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Problem

Adapter\Platform\AbstractPlatform defaulted $quoteIdentifierTo to a single quote. Any platform that keeps the default, Sql92 included, rewrote an embedded " instead of escaping it:

$platform->quoteIdentifier('my"col');   // "my'col"  (names a different column)

Fix

SQL-92 escapes a quote inside a delimited identifier by doubling it, so the default is now '""':

$platform->quoteIdentifier('my"col');   // "my""col"

MySQL ( ``) and PostgreSQL ("") already set this correctly. phpdb-sqlite sets the same wrong value itself and gets its own fix in php-db/phpdb-sqlite.

Tests

  • New data-provider tests in Sql92Test cover a quote inside a name, a lone quote, adjacent quotes, and a single quote left alone. They run against both Sql92 and the bare AbstractPlatform, and they fail without the fix.
  • InsertColumnNameTest and UpdateColumnNameTest had the old output as their expectation for a column named c"d. They now expect "c""d".

mago format --check, mago lint and mago analyze are clean, and the unit suite passes (2,332 tests).

Not changed here

AbstractPlatform defaulted $quoteIdentifierTo to a single quote, so
quoteIdentifier('my"col') rendered "my'col" and named a different
column. SQL-92 escapes an embedded identifier quote by doubling it, so
the default is now '""' and the same name renders "my""col".

The Insert and Update column name tests had the old output as their
expectation for a column named c"d; they now expect "c""d".
@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@simon-mundy simon-mundy self-assigned this Nov 17, 2026
@simon-mundy simon-mundy added bug Something isn't working next minor Target next minor release. labels Nov 17, 2026
@simon-mundy simon-mundy added this to the 0.6.0 milestone Nov 17, 2026
@github-project-automation github-project-automation Bot moved this to Todo in @phpdb Nov 17, 2026
simon-mundy and others added 2 commits November 17, 2026 16:32
The IdentifierQuoter, column-name and ORDER BY tests from php-db#241 and php-db#243
pinned the old SQL-92 escaping, which turned an embedded " into '. With
this PR's fix the quote is doubled, so a"b now renders "a""b".
tyrsson
tyrsson previously approved these changes Nov 17, 2026
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in @phpdb Nov 17, 2026
simon-mundy and others added 2 commits November 17, 2026 16:50
Two Sql92Test cases from php-db#248 pinned the old default replacement, which
turned an opening quote inside an identifier into '. With this PR the
default replacement doubles it, so the expectations become "". The
merge also left a test method out of sorted order; mago format restores
it.
simon-mundy and others added 4 commits November 17, 2026 17:01
PredicateIdentifierNameTest from php-db#244 pinned the old SQL-92 escaping of
an embedded " as '. With this PR the quote is doubled, so a"b renders
"a""b" in every predicate slot.
@simon-mundy
simon-mundy merged commit 008de26 into php-db:0.6.x Nov 17, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in @phpdb Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working next minor Target next minor release.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants