Skip to content

Commit

Permalink
Merge pull request #268 from devlinjunker/master
Browse files Browse the repository at this point in the history
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
rmccue committed Mar 13, 2013
2 parents 5c166b5 + 4d42a89 commit 7040218
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
6 changes: 2 additions & 4 deletions library/SimplePie/Cache/Memcache.php
Expand Up @@ -95,10 +95,8 @@ public function __construct($location, $name, $type)
'prefix' => 'simplepie_', 'prefix' => 'simplepie_',
), ),
); );
$parsed = SimplePie_Cache::parse_URL($location); $this->options = SimplePie_Misc::merge_array_recursive($this->options, 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->name = $this->options['extras']['prefix'] . md5("$name:$type"); $this->name = $this->options['extras']['prefix'] . md5("$name:$type");


$this->cache = new Memcache(); $this->cache = new Memcache();
Expand Down
3 changes: 2 additions & 1 deletion library/SimplePie/Cache/MySQL.php
Expand Up @@ -96,7 +96,8 @@ public function __construct($location, $name, $type)
'prefix' => '', '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 "/" // Path is prefixed with a "/"
$this->options['dbname'] = substr($this->options['path'], 1); $this->options['dbname'] = substr($this->options['path'], 1);
Expand Down
17 changes: 17 additions & 0 deletions library/SimplePie/Misc.php
Expand Up @@ -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) public static function parse_url($url)
{ {
$iri = new SimplePie_IRI($url); $iri = new SimplePie_IRI($url);
Expand Down

0 comments on commit 7040218

Please sign in to comment.