Skip to content

Commit 2ecdb2e

Browse files
authored
Merge pull request #18 from BaguettePHP/feature/pgescape-identifier
Fix PgIdentifier::escape()
2 parents 575b29e + 084412a commit 2ecdb2e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Type/PgIdentifier.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ public function escapeValue($pdo, $key, $type, $value, &$bind_values)
9494
/**
9595
* @phpstan-param string $value
9696
* @phpstan-return non-empty-string
97+
* @see https://github.com/postgres/postgres/blob/REL9_0_STABLE/src/interfaces/libpq/fe-exec.c#L3165-L3169
98+
* @see https://github.com/postgres/postgres/blob/REL_15_STABLE/src/interfaces/libpq/fe-exec.c#L4216-L4220
9799
*/
98100
public function quote($value)
99101
{
100-
return '"' . $value . '"';
102+
return '"' . \strtr($value, ['"' => '""']) . '"';
101103
}
102104
}

tests/Type/PgIdentifierTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public function escapeValuesProvider()
4141
{
4242
return [
4343
['' , '@column', '""'],
44+
['abc' , '@column', '"abc"'],
45+
['ABC' , '@column', '"ABC"'],
46+
['ABC\\ABC\'' , '@column', '"ABC\\ABC\'"'],
47+
['ABC"ABC' , '@column', '"ABC""ABC"'],
48+
['ABC"""ABC' , '@column', '"ABC""""""ABC"'],
4449
[['foo'] , '@column[]', '"foo"'],
4550
[['foo','bar'] , '@column[]', '"foo","bar"'],
4651
[['foo' => 'bar'] , '@column[]', 'foo AS "bar"'],

0 commit comments

Comments
 (0)