mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Reworking how the preq_quote on Query named bindings is applied to help with #580
This commit is contained in:
parent
60ab63b83e
commit
3a0a5e85fd
@ -412,19 +412,21 @@ class Query implements QueryInterface
|
||||
{
|
||||
foreach ($value as &$item)
|
||||
{
|
||||
$item = preg_quote($item);
|
||||
$item = preg_quote($item, '|');
|
||||
}
|
||||
|
||||
$escapedValue = '('.implode(',', $escapedValue).')';
|
||||
}
|
||||
else
|
||||
{
|
||||
$escapedValue = strpos($escapedValue, '\\') !== false
|
||||
? preg_quote(trim($escapedValue, $this->db->escapeChar))
|
||||
: $escapedValue;
|
||||
$escapedValue = preg_quote(trim($escapedValue, $this->db->escapeChar), '|');
|
||||
}
|
||||
|
||||
$sql = preg_replace('/:'.$placeholder.'(?!\w)/', $escapedValue, $sql);
|
||||
// preg_quoting can cause issues with some characters in the final query,
|
||||
// but NOT preg_quoting causes other characters to be intepreted, like $.
|
||||
$escapedValue = str_replace('\\.', '.', $escapedValue);
|
||||
|
||||
$sql = preg_replace('|:'.$placeholder.'(?!\w)|', $escapedValue, $sql);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
|
@ -13,7 +13,7 @@ class Migration_Create_test_tables extends \CodeIgniter\Database\Migration
|
||||
],
|
||||
'name' => [
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 40,
|
||||
'constraint' => 80,
|
||||
],
|
||||
'email' => [
|
||||
'type' => 'VARCHAR',
|
||||
|
@ -6,6 +6,8 @@ class UserModel extends Model
|
||||
{
|
||||
protected $table = 'user';
|
||||
|
||||
protected $allowedFields = ['name', 'email', 'country', 'deleted'];
|
||||
|
||||
protected $returnType = 'object';
|
||||
|
||||
protected $useSoftDeletes = true;
|
||||
|
@ -492,4 +492,26 @@ class ModelTest extends \CIDatabaseTestCase
|
||||
$this->seeInDatabase('job', ['name' => 'Senior Developer']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/bcit-ci/CodeIgniter4/issues/580
|
||||
*/
|
||||
public function testPasswordsStoreCorrectly()
|
||||
{
|
||||
$model = new UserModel();
|
||||
|
||||
$pass = password_hash('secret123', PASSWORD_BCRYPT);
|
||||
|
||||
$data = [
|
||||
'name' => $pass,
|
||||
'email' => 'foo@example.com',
|
||||
'country' => 'US',
|
||||
'deleted' => 0
|
||||
];
|
||||
|
||||
$model->insert($data);
|
||||
|
||||
$this->seeInDatabase('user', $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user