Browse Source

Fixes #16266: Fixed `yii\helpers\BaseStringHelper` where explode would not allow 0 as trim string

tags/2.0.16
Thoulah 6 years ago committed by Alexander Makarov
parent
commit
a32cfcc8ef
  1. 1
      framework/CHANGELOG.md
  2. 2
      framework/helpers/BaseStringHelper.php
  3. 1
      tests/framework/helpers/StringHelperTest.php

1
framework/CHANGELOG.md

@ -22,6 +22,7 @@ Yii Framework 2 Change Log
- Bug #16217: Fixed `yii\console\controllers\HelpController` to work well in Windows environment (samdark) - Bug #16217: Fixed `yii\console\controllers\HelpController` to work well in Windows environment (samdark)
- Bug #14636: Views can now use relative paths even when using themed views (sammousa) - Bug #14636: Views can now use relative paths even when using themed views (sammousa)
- Bug #16245: Fixed `__isset()` in `BaseActiveRecord` not catching errors (sammousa) - Bug #16245: Fixed `__isset()` in `BaseActiveRecord` not catching errors (sammousa)
- Bug #16266: Fixed `yii\helpers\BaseStringHelper` where explode would not allow 0 as trim string (Thoulah)
- Enh #16191: Enhanced `yii\helpers\Inflector` to work correctly with UTF-8 (silverfire) - Enh #16191: Enhanced `yii\helpers\Inflector` to work correctly with UTF-8 (silverfire)
- Bug: Fixed bad instnaceof check in `yii\db\Schema::getTableMetadata()` (samdark) - Bug: Fixed bad instnaceof check in `yii\db\Schema::getTableMetadata()` (samdark)

2
framework/helpers/BaseStringHelper.php

@ -269,7 +269,7 @@ class BaseStringHelper
public static function explode($string, $delimiter = ',', $trim = true, $skipEmpty = false) public static function explode($string, $delimiter = ',', $trim = true, $skipEmpty = false)
{ {
$result = explode($delimiter, $string); $result = explode($delimiter, $string);
if ($trim) { if ($trim !== false) {
if ($trim === true) { if ($trim === true) {
$trim = 'trim'; $trim = 'trim';
} elseif (!is_callable($trim)) { } elseif (!is_callable($trim)) {

1
tests/framework/helpers/StringHelperTest.php

@ -267,6 +267,7 @@ class StringHelperTest extends TestCase
$this->assertEquals(['It', 'is', 'a test with trimmed digits', '0', '1', '2'], StringHelper::explode('It, is, a test with trimmed digits, 0, 1, 2', ',', true, true)); $this->assertEquals(['It', 'is', 'a test with trimmed digits', '0', '1', '2'], StringHelper::explode('It, is, a test with trimmed digits, 0, 1, 2', ',', true, true));
$this->assertEquals(['It', 'is', 'a second', 'test'], StringHelper::explode('It+ is+ a second+ test', '+')); $this->assertEquals(['It', 'is', 'a second', 'test'], StringHelper::explode('It+ is+ a second+ test', '+'));
$this->assertEquals(['Save', '', '', 'empty trimmed string'], StringHelper::explode('Save, ,, empty trimmed string', ',')); $this->assertEquals(['Save', '', '', 'empty trimmed string'], StringHelper::explode('Save, ,, empty trimmed string', ','));
$this->assertEquals(['44', '512'], StringHelper::explode('0 0 440 512', ' ', '0', true));
$this->assertEquals(['Здесь', 'multibyte', 'строка'], StringHelper::explode('Здесь我 multibyte我 строка', '我')); $this->assertEquals(['Здесь', 'multibyte', 'строка'], StringHelper::explode('Здесь我 multibyte我 строка', '我'));
$this->assertEquals(['Disable', ' trim ', 'here but ignore empty'], StringHelper::explode('Disable, trim ,,,here but ignore empty', ',', false, true)); $this->assertEquals(['Disable', ' trim ', 'here but ignore empty'], StringHelper::explode('Disable, trim ,,,here but ignore empty', ',', false, true));
$this->assertEquals(['It/', ' is?', ' a', ' test with rtrim'], StringHelper::explode('It/, is?, a , test with rtrim', ',', 'rtrim')); $this->assertEquals(['It/', ' is?', ' a', ' test with rtrim'], StringHelper::explode('It/, is?, a , test with rtrim', ',', 'rtrim'));

Loading…
Cancel
Save