From e32b2b1370c6be07814c82ed33ffb9d0c259a8a9 Mon Sep 17 00:00:00 2001 From: Alexander Grigorev Date: Fri, 11 Nov 2016 15:11:30 +0300 Subject: [PATCH 1/6] Fix string length In different encodings such as UTF-8, the validator incorrectly believed the string length --- lib/Validations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Validations.php b/lib/Validations.php index 64a58cfa5..8e8e7a3d6 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); $value = (int)$attr[$range_option]; if ('maximum' == $range_option && $len > $value) From 8bebeab6c46f8e20b13653652490b99deb1e87b2 Mon Sep 17 00:00:00 2001 From: Alexander Grigorev Date: Sun, 13 Nov 2016 04:12:20 +0300 Subject: [PATCH 2/6] Update ValidatesLengthOfTest.php --- test/ValidatesLengthOfTest.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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 +?> From c31a7a30f4180b6af3bd9fde851267ea106e838a Mon Sep 17 00:00:00 2001 From: Alexander Grigorev Date: Sun, 13 Nov 2016 04:15:43 +0300 Subject: [PATCH 3/6] Update composer.json Pear log 1.12 is not working with php 7, and a newer version requires a stable pear_exception --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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" ] From 1f3ac3d83aae068742ce066e792e49d949489518 Mon Sep 17 00:00:00 2001 From: Alexander Grigorev Date: Sun, 13 Nov 2016 04:21:51 +0300 Subject: [PATCH 4/6] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 9f9f1caca..63f932948 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,8 @@ }, "require-dev": { "phpunit/phpunit": "4.*", - "pear/pear_exception": "^1.0", - "pear/log": "^1.13" + "pear/pear_exception": "1.0-beta1", + "pear/log": "~1.12" }, "autoload": { "files": [ "ActiveRecord.php" ] From bb0e8015390ba39b758e0472ad8e3f534e03881a Mon Sep 17 00:00:00 2001 From: Alexander Grigorev Date: Sun, 13 Nov 2016 04:34:29 +0300 Subject: [PATCH 5/6] Update Validations.php --- lib/Validations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Validations.php b/lib/Validations.php index 8e8e7a3d6..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 = mb_strlen($attribute_value); + $len = mb_strlen($attribute_value, 'UTF-8'); $value = (int)$attr[$range_option]; if ('maximum' == $range_option && $len > $value) From cf3120e3040ad790affe02eb5a25d6a7d3263183 Mon Sep 17 00:00:00 2001 From: Alexander Grigorev Date: Sun, 13 Nov 2016 04:41:39 +0300 Subject: [PATCH 6/6] Update composer.json Pear log 1.12 is not working with php 7, and a newer version requires a stable pear_exception --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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" ]