Permalink
Browse files

Merge pull request #268 from devlinjunker/master

Fix database URL parsing when merging with defaults

Previously, options which had a default and were strings were turned into
arrays by `array_merge_recursive`. This fixes that behaviour by implementing a
more sane recursive merge.
  • Loading branch information...
2 parents 5c166b5 + 4d42a89 commit 70402181a5c9e2660c1e1337ade7c160d1936ebe @rmccue rmccue committed Mar 13, 2013
Showing with 21 additions and 5 deletions.
  1. +2 −4 library/SimplePie/Cache/Memcache.php
  2. +2 −1 library/SimplePie/Cache/MySQL.php
  3. +17 −0 library/SimplePie/Misc.php
@@ -95,10 +95,8 @@ public function __construct($location, $name, $type)
'prefix' => 'simplepie_',
),
);
- $parsed = SimplePie_Cache::parse_URL($location);
- $this->options['host'] = empty($parsed['host']) ? $this->options['host'] : $parsed['host'];
- $this->options['port'] = empty($parsed['port']) ? $this->options['port'] : $parsed['port'];
- $this->options['extras'] = array_merge($this->options['extras'], $parsed['extras']);
+ $this->options = SimplePie_Misc::merge_array_recursive($this->options, SimplePie_Cache::parse_URL($location);
+
$this->name = $this->options['extras']['prefix'] . md5("$name:$type");
$this->cache = new Memcache();
@@ -96,7 +96,8 @@ public function __construct($location, $name, $type)
'prefix' => '',
),
);
- $this->options = array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
+
+ $this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
// Path is prefixed with a "/"
$this->options['dbname'] = substr($this->options['path'], 1);
View
@@ -224,6 +224,23 @@ public static function fix_protocol($url, $http = 1)
}
}
+ public static function array_merge_recursive($array1, $array2)
+ {
+ foreach ($array2 as $key => $value)
+ {
+ if (is_array($value))
+ {
+ $array1[$key] = SimplePie_Misc::array_merge_recursive($array1[$key], $value);
+ }
+ else
+ {
+ $array1[$key] = $value;
+ }
+ }
+
+ return $array1;
+ }
+
public static function parse_url($url)
{
$iri = new SimplePie_IRI($url);

0 comments on commit 7040218

Please sign in to comment.