Skip to content

Commit edaaaa1

Browse files
authored
Escape with single-quote to be compatible with PostgreSQL (#10)
1 parent 38c6ba2 commit edaaaa1

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"php": "~8.1.0 || ~8.2.0"
1515
},
1616
"require-dev": {
17-
"phpunit/phpunit": "^10.0.11",
18-
"slam/php-cs-fixer-extensions": "^3.4"
17+
"phpunit/phpunit": "^10.4.1",
18+
"slam/php-cs-fixer-extensions": "^3.9"
1919
},
2020
"autoload": {
2121
"files": [

lib/r.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function rq(
3131
foreach ($params as $key => $value) {
3232
$query = \str_replace(
3333
\sprintf(':%s', $key),
34-
\sprintf('"%s"', \str_replace('"', '\\"', (string) $value)),
34+
\sprintf('\'%s\'', \str_replace('\'', '\\\'', (string) $value)),
3535
$query
3636
);
3737
}
@@ -47,9 +47,7 @@ final class R
4747
{
4848
public static array $db = [];
4949

50-
private function __construct()
51-
{
52-
}
50+
private function __construct() {}
5351

5452
public static function debug(
5553
mixed $var,
@@ -249,9 +247,7 @@ private static function fillReturnWithClassAttributes(object $var, \stdClass $re
249247
return $return;
250248
}
251249

252-
/**
253-
* Gets the real class name of a class name that could be a proxy.
254-
*/
250+
/** Gets the real class name of a class name that could be a proxy. */
255251
private static function getRealClass(string $class): string
256252
{
257253
if (! \class_exists(Proxy::class) || false === ($pos = \strrpos($class, '\\' . Proxy::MARKER . '\\'))) {
@@ -261,9 +257,7 @@ private static function getRealClass(string $class): string
261257
return \substr($class, (int) ($pos + Proxy::MARKER_LENGTH + 2));
262258
}
263259

264-
/**
265-
* Gets the real class name of an object (even if its a proxy).
266-
*/
260+
/** Gets the real class name of an object (even if its a proxy). */
267261
private static function getClass(object $object): string
268262
{
269263
return self::getRealClass($object::class);

phpunit.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
cacheDirectory=".phpunit.cache"
77
>
88
<coverage>
9-
<include>
10-
<directory suffix=".php">./lib</directory>
11-
</include>
129
<report>
1310
<text outputFile="php://stdout" showOnlySummary="true"/>
1411
</report>
1512
</coverage>
1613
<testsuite name="Debug_R">
1714
<directory>./tests</directory>
1815
</testsuite>
16+
<source>
17+
<include>
18+
<directory>./lib</directory>
19+
</include>
20+
</source>
1921
</phpunit>

tests/RTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ final class RTest extends TestCase
1414

1515
private static bool $isStreamFilterRegistered = false;
1616

17-
/**
18-
* @var resource
19-
*/
17+
/** @var resource */
2018
private $registeredFilter;
2119

2220
protected function setUp(): void
@@ -73,9 +71,9 @@ public function testStripEntriesFromFullstack(): void
7371

7472
public function testQueryDebug(): void
7573
{
76-
rq('SELECT * FROM table WHERE c1 = :p1 AND c1 = :p11 AND c1 = :p2', ['p1' => 1, 'p11' => 2, 'p2' => '"'], false, 0, true);
74+
rq('SELECT * FROM table WHERE c1 = :p1 AND c1 = :p11 AND c1 = :p2', ['p1' => 1, 'p11' => 2, 'p2' => '\''], false, 0, true);
7775

78-
self::assertStringContainsString('SELECT * FROM table WHERE c1 = "1" AND c1 = "2" AND c1 = "\\""', MockStderr::$output);
76+
self::assertStringContainsString('SELECT * FROM table WHERE c1 = \'1\' AND c1 = \'2\' AND c1 = \'\\\'\'', MockStderr::$output);
7977
}
8078

8179
public function testDoctrine(): void

0 commit comments

Comments
 (0)