diff --git a/composer.json b/composer.json index 63f932948..9f9f1caca 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,8 @@ }, "require-dev": { "phpunit/phpunit": "4.*", - "pear/pear_exception": "1.0-beta1", - "pear/log": "~1.12" + "pear/pear_exception": "^1.0", + "pear/log": "^1.13" }, "autoload": { "files": [ "ActiveRecord.php" ] diff --git a/lib/Validations.php b/lib/Validations.php index 64a58cfa5..3b567ad41 100644 --- a/lib/Validations.php +++ b/lib/Validations.php @@ -521,7 +521,7 @@ public function validates_length_of($attrs) $message = str_replace('%d', $option, $message); $attribute_value = $this->model->$attribute; - $len = strlen($attribute_value); + $len = mb_strlen($attribute_value, 'UTF-8'); $value = (int)$attr[$range_option]; if ('maximum' == $range_option && $len > $value) diff --git a/test/ValidatesLengthOfTest.php b/test/ValidatesLengthOfTest.php index bd93a1d80..362f45ffa 100644 --- a/test/ValidatesLengthOfTest.php +++ b/test/ValidatesLengthOfTest.php @@ -356,5 +356,26 @@ public function test_validates_length_of_is() $book->is_valid(); $this->assert_equals(array("Name is the wrong length (should be 2 characters)"),$book->errors->full_messages()); } + + public function test_validates_length_utf8_of_maximum() + { + BookLength::$validates_length_of[0] = array('name', 'maximum' => 10); + $book = new BookLength(array('name' => 'абвгдеё')); + $this->assert_true($book->is_valid('name')); + } + + public function test_validates_length_utf8_of_minimum() + { + BookLength::$validates_length_of[0] = array('name', 'minimum' => 3); + $book = new BookLength(array('name' => 'аб')); + $this->assert_true($book->is_invalid('name')); + } + + public function test_validates_length_utf8_of_is() + { + BookLength::$validates_length_of[0] = array('name', 'is' => 6); + $book = new BookLength(array('name' => 'АаЁёЯя')); + $this->assert_true($book->is_valid('name')); + } }; -?> \ No newline at end of file +?>