Fix #4516
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 296ddb9..09d6c9a 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -583,7 +583,10 @@
protected function _execute($row, $rules, $postdata = NULL, $cycles = 0)
{
// If the $_POST data is an array we will run a recursive call
- if (is_array($postdata))
+ //
+ // Note: We MUST check if the array is empty or not!
+ // Otherwise empty arrays will always pass validation.
+ if (is_array($postdata) && ! empty($postdata))
{
foreach ($postdata as $key => $val)
{
diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php
index f455b91..3537eb3 100644
--- a/tests/codeigniter/libraries/Form_validation_test.php
+++ b/tests/codeigniter/libraries/Form_validation_test.php
@@ -28,6 +28,16 @@
$this->form_validation = new CI_Form_validation();
}
+ public function test_empty_array_input()
+ {
+ $this->assertFalse(
+ $this->run_rules(
+ array(array('field' => 'foo', 'label' => 'Foo Label', 'rules' => 'required')),
+ array('foo' => array())
+ )
+ );
+ }
+
public function test_rule_required()
{
$rules = array(array('field' => 'foo', 'label' => 'foo_label', 'rules' => 'required'));
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 1492b30..2278412 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -7,6 +7,10 @@
Release Date: Not Released
+Bug fixes for 3.0.6
+-------------------
+
+- Fixed a bug (#4516) - :doc:`Form Validation Library <libraries/form_validation>` always accepted empty array inputs.
Version 3.0.5
=============