Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Loss of escape value and data in the model #4087

Closed
iRedds opened this issue Jan 9, 2021 · 0 comments · Fixed by #4088
Closed

Bug: Loss of escape value and data in the model #4087

iRedds opened this issue Jan 9, 2021 · 0 comments · Fixed by #4088
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@iRedds
Copy link
Collaborator

iRedds commented Jan 9, 2021

Each time the Model::set() method is called, the value of $this->tempData['escape'] is overridden.

public function set($key, ?string $value = '', ?bool $escape = null)
{
$data = is_array($key) ? $key : [$key => $value];
$this->tempData['escape'] = $escape;
$this->tempData['data'] = array_merge($this->tempData['data'] ?? [], $data);
return $this;
}

// escape value is lost
$model = new OurModel();
$model->set('key', 'NOW()', false) //no escape
	->set('key2', 'value')
	->insert();

// INSERT INTO `some_table` (`key`, `key2`) VALUES ('NOW()', 'value')

If data is passed to the Model::insert() or Model::update() methods, then the data passed through the Model::set() method are ignored

public function insert($data = null, bool $returnID = true)
{
if (empty($data))
{
$data = $this->tempData['data'] ?? null;
$this->escape = $this->tempData['escape'] ?? null;
$this->tempData = [];
}
return parent::insert($data, $returnID);
}

// data is lost
$model = new OurModel();
$model->set('key', 'NOW()')
	->insert(['key2' => 'value']);
//INSERT INTO `some_table` (`key2`) VALUES ('value')"

CodeIgniter 4 version
4.0.4 & Develop branch

Affected module(s)
Codeigniter\Model

@iRedds iRedds added the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant