diff --git a/cache/stores/memcache/lib.php b/cache/stores/memcache/lib.php index 1569da6bd80..c71f1080160 100644 --- a/cache/stores/memcache/lib.php +++ b/cache/stores/memcache/lib.php @@ -350,7 +350,12 @@ class cachestore_memcache extends cache_store implements cache_is_configurable { $lines = explode("\n", $data->servers); $servers = array(); foreach ($lines as $line) { - $line = trim($line, ':'); + // Trim surrounding colons and default whitespace. + $line = trim(trim($line), ":"); + // Skip blank lines. + if ($line === '') { + continue; + } $servers[] = explode(':', $line, 3); } return array( diff --git a/cache/stores/memcached/lib.php b/cache/stores/memcached/lib.php index 508628e3883..1bce7aab7e1 100644 --- a/cache/stores/memcached/lib.php +++ b/cache/stores/memcached/lib.php @@ -374,7 +374,12 @@ class cachestore_memcached extends cache_store implements cache_is_configurable $lines = explode("\n", $data->servers); $servers = array(); foreach ($lines as $line) { - $line = trim($line, ':'); + // Trim surrounding colons and default whitespace. + $line = trim(trim($line), ":"); + // Skip blank lines. + if ($line === '') { + continue; + } $servers[] = explode(':', $line, 3); } return array(