Skip to content

Commit 19c173a

Browse files
committed
Quoting negative numbers when escaping the value. See #606
1 parent b6cb30b commit 19c173a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

system/Database/BaseConnection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,10 @@ public function escape($str)
13191319
{
13201320
return ($str === false) ? 0 : 1;
13211321
}
1322+
else if (is_numeric($str) && $str < 0)
1323+
{
1324+
return "'{$str}'";
1325+
}
13221326
else if ($str === null)
13231327
{
13241328
return 'NULL';

tests/system/Database/BaseConnectionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,19 @@ public function testStoresConnectionTimings()
131131

132132
//--------------------------------------------------------------------
133133

134+
/**
135+
* Ensures we don't have escaped - values...
136+
*
137+
* @see https://github.com/bcit-ci/CodeIgniter4/issues/606
138+
*/
139+
public function testEscapeProtectsNegativeNumbers()
140+
{
141+
$db = new MockConnection($this->options);
142+
143+
$db->initialize();
144+
145+
$this->assertEquals("'-100'", $db->escape(-100));
146+
}
147+
134148

135149
}

0 commit comments

Comments
 (0)