Browse Source

Merge pull request #9912 from SilverFire/9911-string-helper-explode-bug

Fixed #9911 - StringHelper::explode with skip_empty option removed item eq to 0
tags/3.0.0-alpha1
Alexander Makarov 9 years ago
parent
commit
7b6d39b3e7
  1. 1
      framework/CHANGELOG.md
  2. 4
      framework/helpers/BaseStringHelper.php
  3. 1
      tests/framework/helpers/StringHelperTest.php

1
framework/CHANGELOG.md

@ -23,6 +23,7 @@ Yii Framework 2 Change Log
- Bug #9791: Fixed endless loop on file creation for non-existing device letters on windows (lukos, cebe)
- Bug #9874: Fixed outputting exception stacktrace in non-debug mode when `Response::FORMAT_RAW` is used (nainoon)
- Bug #9883: Passing a single `yii\db\Expression` to `Query::select()` or `::addSelect()` was not handled correctly in all cases (cebe)
- Bug #9911: Fixed `yii\helpers\BaseStringHelper::explode()` code so it does not remove items eq to 0 with skip_empty attribute (silverfire, kidol)
- Bug: Fixed generation of canonical URLs for `ViewAction` pages (samdark)
- Enh #7581: Added ability to specify range using anonymous function in `RangeValidator` (RomeroMsk)
- Enh #8613: `yii\widgets\FragmentCache` will not store empty content anymore which fixes some problems related to `yii\filters\PageCache` (kidol)

4
framework/helpers/BaseStringHelper.php

@ -264,7 +264,9 @@ class BaseStringHelper
}
if ($skipEmpty) {
// Wrapped with array_values to make array keys sequential after empty values removing
$result = array_values(array_filter($result));
$result = array_values(array_filter($result, function ($value) {
return $value !== '';
}));
}
return $result;
}

1
tests/framework/helpers/StringHelperTest.php

@ -231,6 +231,7 @@ class StringHelperTest extends TestCase
public function testExplode()
{
$this->assertEquals(['It', 'is', 'a first', 'test'], StringHelper::explode("It, is, a first, test"));
$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(['Save', '', '', 'empty trimmed string'], StringHelper::explode("Save, ,, empty trimmed string", ','));
$this->assertEquals(['Здесь', 'multibyte', 'строка'], StringHelper::explode("Здесь我 multibyte我 строка", '我'));

Loading…
Cancel
Save