Skip to content

Commit

Permalink
Add Input Array checking before sanitization to avoid returning null …
Browse files Browse the repository at this point in the history
…when array size is 0
  • Loading branch information
rawuf-abdel committed Mar 22, 2022
1 parent aef79b0 commit 03e5f61
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/mandryn_v1/MagicInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ public function toArray() {
* @param boolean $apply_sanitize sanitize input before assign to object. Default to true.
*/
public function copy_GET_properties($apply_sanitize = true) {

$GET_array = $apply_sanitize ? filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING) : $_GET;

$GET_array = [];

if($this->is_non_empty_array($_GET)){
$GET_array = $apply_sanitize ? filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING) : $_GET;
}

$this->copyArrayProperties($GET_array, true);
}

Expand All @@ -239,9 +242,12 @@ public function copy_GET_properties($apply_sanitize = true) {
* @param boolean $apply_sanitize sanitize input before assign to object. Default to true.
*/
public function copy_POST_properties($apply_sanitize = true) {

$POST_array = $apply_sanitize ? filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING) : $_POST;

$POST_array = [];

if($this->is_non_empty_array($_POST)){
$POST_array = $apply_sanitize ? filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING) : $_POST;
}

$this->copyArrayProperties($POST_array, true);
}

Expand All @@ -263,5 +269,13 @@ public function copy_RAW_JSON_properties($apply_sanitize = true) {
$this->copyArrayProperties($input);
}
}

private function is_non_empty_array($array){
if(is_array($array)){
return count($array)>0?true:false;
}else{
return false;
}
}

}

0 comments on commit 03e5f61

Please sign in to comment.