Skip to content

Commit 0aeecec

Browse files
[10.x] Throw exception when trying to escape array for database connection (#48836)
* Throw error when trying to escape array * Add tests to test escaping array throwing exception * Update Connection.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 6f06ad4 commit 0aeecec

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

src/Illuminate/Database/Connection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,8 @@ public function escape($value, $binary = false)
11011101
return (string) $value;
11021102
} elseif (is_bool($value)) {
11031103
return $this->escapeBool($value);
1104+
} elseif (is_array($value)) {
1105+
throw new RuntimeException('The database connection does not support escaping arrays.');
11041106
} else {
11051107
if (str_contains($value, "\00")) {
11061108
throw new RuntimeException('Strings with null bytes cannot be escaped. Use the binary escape option.');

tests/Integration/Database/MySql/EscapeTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,11 @@ public function testEscapeStringNullByte()
6161

6262
$this->app['db']->escape("I am hiding a \00 byte");
6363
}
64+
65+
public function testEscapeArray()
66+
{
67+
$this->expectException(RuntimeException::class);
68+
69+
$this->app['db']->escape(['a', 'b']);
70+
}
6471
}

tests/Integration/Database/Postgres/EscapeTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,11 @@ public function testEscapeStringNullByte()
6161

6262
$this->app['db']->escape("I am hiding a \00 byte");
6363
}
64+
65+
public function testEscapeArray()
66+
{
67+
$this->expectException(RuntimeException::class);
68+
69+
$this->app['db']->escape(['a', 'b']);
70+
}
6471
}

tests/Integration/Database/SqlServer/EscapeTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,11 @@ public function testEscapeStringNullByte()
5757

5858
$this->app['db']->escape("I am hiding a \00 byte");
5959
}
60+
61+
public function testEscapeArray()
62+
{
63+
$this->expectException(RuntimeException::class);
64+
65+
$this->app['db']->escape(['a', 'b']);
66+
}
6067
}

tests/Integration/Database/Sqlite/EscapeTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,11 @@ public function testEscapeStringNullByte()
7373

7474
$this->app['db']->escape("I am hiding a \00 byte");
7575
}
76+
77+
public function testEscapeArray()
78+
{
79+
$this->expectException(RuntimeException::class);
80+
81+
$this->app['db']->escape(['a', 'b']);
82+
}
7683
}

0 commit comments

Comments
 (0)