Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
2 changes: 1 addition & 1 deletion lib/Validations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 22 additions & 1 deletion test/ValidatesLengthOfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
};
?>
?>