Skip to content

Commit d000621

Browse files
authored
Merge pull request #52 from DenislavParvanov/master
Change strlen to mb_strlen
2 parents 3af4f0b + 3928cd5 commit d000621

File tree

5 files changed

+7
-4
lines changed

5 files changed

+7
-4
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
}
1515
},
1616
"require": {
17-
"php": ">=5.5.0"
17+
"php": ">=5.5.0",
18+
"ext-mbstring": "*"
1819
},
1920
"require-dev": {
2021
"phpunit/phpunit": "4.*"

src/Rules/Between.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function check($value)
2121
if (is_int($value)) {
2222
return $value >= $min AND $value <= $max;
2323
} elseif(is_string($value)) {
24-
return strlen($value) >= $min AND strlen($value) <= $max;
24+
return mb_strlen($value, 'UTF-8') >= $min AND mb_strlen($value, 'UTF-8') <= $max;
2525
} elseif(is_array($value)) {
2626
return count($value) >= $min AND count($value) <= $max;
2727
} else {

src/Rules/Required.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function check($value)
2020
return $this->isValueFromUploadedFiles($value) AND $value['error'] != UPLOAD_ERR_NO_FILE;
2121
}
2222

23-
if (is_string($value)) return strlen(trim($value)) > 0;
23+
if (is_string($value)) return mb_strlen(trim($value), 'UTF-8') > 0;
2424
if (is_array($value)) return count($value) > 0;
2525
return !is_null($value);
2626
}

src/Validation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ protected function initializeAttributeOnData($attributeKey)
162162

163163
$asteriskPos = strpos($attributeKey, '*');
164164

165-
if (false === $asteriskPos || $asteriskPos === (strlen($attributeKey) - 1)) {
165+
if (false === $asteriskPos || $asteriskPos === (mb_strlen($attributeKey, 'UTF-8') - 1)) {
166166
return $data;
167167
}
168168

tests/Rules/BetweenTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ public function setUp()
1313
public function testValids()
1414
{
1515
$this->assertTrue($this->rule->fillParameters([6, 10])->check('foobar'));
16+
$this->assertTrue($this->rule->fillParameters([6, 10])->check('футбол'));
1617
$this->assertTrue($this->rule->fillParameters([2, 3])->check([1,2,3]));
1718
$this->assertTrue($this->rule->fillParameters([100, 150])->check(123));
1819
}
1920

2021
public function testInvalids()
2122
{
2223
$this->assertFalse($this->rule->fillParameters([2, 5])->check('foobar'));
24+
$this->assertFalse($this->rule->fillParameters([2, 5])->check('футбол'));
2325
$this->assertFalse($this->rule->fillParameters([4, 6])->check([1,2,3]));
2426
$this->assertFalse($this->rule->fillParameters([50, 100])->check(123));
2527
}

0 commit comments

Comments
 (0)