Fixes #16648: Html::strtolower() was corrupting UTF-8 strings

This commit is contained in:
Nikolay Oleynikov
2018-11-20 01:09:03 +03:00
committed by Alexander Makarov
parent 383953d9b7
commit 06227c7075
3 changed files with 55 additions and 1 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.16 under development
------------------------
- Bug #16648: Html::strtolower() was corrupting UTF-8 strings (Kolyunya)
- Bug #13977: Skip validation if file input does not exist (RobinKamps, s1lver)
- Bug #16183: Fixed when `yii\helpers\BaseFileHelper` sometimes returned wrong value (samdark, SilverFire, OndrejVasicek)
- Bug #13932: Fix number validator attributes comparison (uaoleg, s1lver)

View File

@ -2295,7 +2295,8 @@ class BaseHtml
*/
public static function getInputId($model, $attribute)
{
$name = strtolower(static::getInputName($model, $attribute));
$charset = Yii::$app ? Yii::$app->charset : 'UTF-8';
$name = mb_strtolower(static::getInputName($model, $attribute), $charset);
return str_replace(['[]', '][', '[', ']', ' ', '.'], ['', '-', '-', '', '-', '-'], $name);
}

View File

@ -1778,6 +1778,19 @@ EOD;
$this->assertSame($expected, $actual);
}
/**
* @dataProvider testGetInputIdDataProvider
*/
public function testGetInputId($attributeName, $inputIdExpected)
{
$model = new DynamicModel();
$model->defineAttribute($attributeName);
$inputIdActual = Html::getInputId($model, $attributeName);
$this->assertSame($inputIdExpected, $inputIdActual);
}
public function testEscapeJsRegularExpression()
{
$expected = '/[a-z0-9-]+/';
@ -1858,6 +1871,45 @@ HTML;
$this->assertContains('placeholder="My placeholder: Name"', $html);
}
public function testGetInputIdDataProvider()
{
return [
[
'foo',
'dynamicmodel-foo',
],
[
'FooBar',
'dynamicmodel-foobar',
],
[
'Foo_Bar',
'dynamicmodel-foo_bar',
],
[
'foo[]',
'dynamicmodel-foo',
],
[
'foo[bar][baz]',
'dynamicmodel-foo-bar-baz',
],
[
'foo.bar',
'dynamicmodel-foo-bar',
],
[
'bild_groß_dateiname',
'dynamicmodel-bild_groß_dateiname',
],
[
'ФуБарБаз',
'dynamicmodel-фубарбаз',
],
];
}
}
/**