Skip to content

Commit

Permalink
Fix array check issues
Browse files Browse the repository at this point in the history
Fix issues when calling array_key_exists with a null $key or $section
value, or improperly parsed $sec value.
  • Loading branch information
d8ahazard authored and pce committed Dec 14, 2016
1 parent 692c9fd commit 60357d8
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions Config/Lite.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,11 @@ public function get($sec = null, $key = null, $default = null)
if ((null === $sec) && (null === $key) && (null === $default)) {
return $this->sections;
}
if ((null !== $sec) && array_key_exists($sec, $this->sections)
&& isset($this->sections[$sec][$key])
) {
return $this->sections[$sec][$key];
}
if (is_array($this->sections)) {
if ((null !== $sec) && array_key_exists(strval($sec), $this->sections) && isset($this->sections[$sec][$key])) {
return $this->sections[$sec][$key];
}
}
// global value
if ((null === $sec) && array_key_exists($key, $this->sections)) {
return $this->sections[$key];
Expand Down Expand Up @@ -461,23 +461,24 @@ public function getBool($sec, $key, $default = null)
return $this->_booleans[$value];
}
}
}
if (array_key_exists($key, $this->sections[$sec])) {
if (empty($this->sections[$sec][$key])) {
return false;
}
$value = strtolower($this->sections[$sec][$key]);
if (!in_array($value, $this->_booleans) && (null === $default)) {
throw new Config_Lite_Exception_InvalidArgument(
sprintf(
'Not a boolean: %s, and no default value given.',
$value
)
);
} else {
return $this->_booleans[$value];
}
}
} else if (is_array($this->sections[strval($sec)])) {
if (array_key_exists($key, $this->sections[$sec])) {
if (empty($this->sections[$sec][$key])) {
return false;
}
$value = strtolower($this->sections[$sec][$key]);
if (!in_array($value, $this->_booleans) && (null === $default)) {
throw new Config_Lite_Exception_InvalidArgument(
sprintf(
'Not a boolean: %s, and no default value given.',
$value
)
);
} else {
return $this->_booleans[$value];
}
}
}
if (null !== $default) {
return $default;
}
Expand Down

0 comments on commit 60357d8

Please sign in to comment.