Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added multibyte string encoding consideration with tests #39

Merged
merged 1 commit into from
Sep 19, 2019
Merged
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
2 changes: 1 addition & 1 deletion src/Filters/Capitalize.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class Capitalize implements Filter
*/
public function apply($value, $options = [])
{
return is_string($value) ? ucwords(strtolower($value)) : $value;
return is_string($value) ? mb_convert_case(mb_strtolower($value, 'UTF-8'), MB_CASE_TITLE) : $value;
}
}
2 changes: 1 addition & 1 deletion src/Filters/Lowercase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class Lowercase implements Filter
*/
public function apply($value, $options = [])
{
return is_string($value) ? strtolower($value) : $value;
return is_string($value) ? mb_strtolower($value, 'UTF-8') : $value;
}
}
2 changes: 1 addition & 1 deletion src/Filters/Uppercase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class Uppercase implements Filter
*/
public function apply($value, $options = [])
{
return is_string($value) ? strtoupper($value) : $value;
return is_string($value) ? mb_strtoupper($value) : $value;
}
}
9 changes: 9 additions & 0 deletions tests/Filters/CapitalizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ public function it_capitalizes_strings()
$result = $this->sanitize(['name' => ' jon snow 145'], ['name' => 'capitalize']);
$this->assertEquals(' Jon Snow 145', $result['name']);
}

/**
* @test
*/
public function it_capitalizes_special_characters()
{
$result = $this->sanitize(['name' => 'Τάχιστη αλώπηξ'], ['name' => 'capitalize']);
$this->assertEquals('Τάχιστη Αλώπηξ', $result['name']);
}
}
15 changes: 15 additions & 0 deletions tests/Filters/LowercaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ public function it_lowercases_strings()
$data = $this->sanitize($data, $rules);
$this->assertEquals('hello everybody', $data['name']);
}

/**
* @test
*/
public function it_lowercases_special_characters_strings()
{
$data = [
'name' => 'Τάχιστη αλώπηξ',
];
$rules = [
'name' => 'lowercase',
];
$data = $this->sanitize($data, $rules);
$this->assertEquals('τάχιστη αλώπηξ', $data['name']);
}
}
15 changes: 15 additions & 0 deletions tests/Filters/UppercaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ public function it_uppercases_strings()
$data = $this->sanitize($data, $rules);
$this->assertEquals('HELLO EVERYBODY', $data['name']);
}

/**
* @test
*/
public function it_uppercases_special_characters_strings()
{
$data = [
'name' => 'Τάχιστη αλώπηξ',
];
$rules = [
'name' => 'uppercase',
];
$data = $this->sanitize($data, $rules);
$this->assertEquals('ΤΆΧΙΣΤΗ ΑΛΏΠΗΞ', $data['name']);
}
}