Browse Source

Add rcube_utils::explode()

pull/7707/head
Aleksander Machniak 5 years ago
parent
commit
318f91417f
  1. 7
      program/lib/Roundcube/rcube_contacts.php
  2. 18
      program/lib/Roundcube/rcube_utils.php
  3. 9
      tests/Framework/Utils.php

7
program/lib/Roundcube/rcube_contacts.php

@ -757,12 +757,7 @@ class rcube_contacts extends rcube_addressbook
unset($save_data['groups']);
foreach ($save_data as $key => $values) {
$field = $key;
$section = '';
if (strpos($field, ':') > 0) {
list($field, $section) = explode(':', $field);
}
list($field, $section) = rcube_utils::explode(':', $key);
$fulltext = in_array($field, $this->fulltext_cols);

18
program/lib/Roundcube/rcube_utils.php

@ -35,6 +35,24 @@ class rcube_utils
const INPUT_GPC = 7; // GET + POST + COOKIE
/**
* A wrapper for PHP's explode() that does not throw a warning
* when the separator does not exist in the string
*
* @param string $separator Separator string
* @param string $string The string to explode
*
* @return array Exploded string. Still an array if there's no separator in the string
*/
public static function explode($separator, $string)
{
if (strpos($string, $separator) !== false) {
return explode($separator, $string);
}
return [$string, null];
}
/**
* Helper method to set a cookie with the current path and host settings
*

9
tests/Framework/Utils.php

@ -7,6 +7,15 @@
*/
class Framework_Utils extends PHPUnit\Framework\TestCase
{
/**
* Test for rcube_utils::explode()
*/
function test_explode()
{
$this->assertSame(['test', null], rcube_utils::explode(':', 'test'));
$this->assertSame(['test1', 'test2'], rcube_utils::explode(':', 'test1:test2'));
$this->assertSame(['', 'test1', 'test2'], rcube_utils::explode(':', ':test1:test2'));
}
/**
* Valid email addresses for test_valid_email()

Loading…
Cancel
Save