Skip to content

Commit

Permalink
Do not crash when generating URLs with arrays as parameters (#2018)
Browse files Browse the repository at this point in the history
When using a default image derivatives (#1979) setting like

  images:
    defaults:
      derivatives: [300,600]

then Grav crashes when a video gets embedded.
The following error occurs:

  rawurlencode() expects parameter 1 to be string, array given
  system/src/Grav/Common/Page/Medium/Medium.php:521

This patch encodes array URL parameters correctly.
  • Loading branch information
Christian Weiske authored and rhukster committed May 15, 2018
1 parent e1d5218 commit 7f90ad8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion system/src/Grav/Common/Page/Medium/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,12 @@ public function __call($method, $args)
{
$qs = $method;
if (count($args) > 1 || (count($args) == 1 && !empty($args[0]))) {
$qs .= '=' . implode(',', array_map(function ($a) { return rawurlencode($a); }, $args));
$qs .= '=' . implode(',', array_map(function ($a) {
if (is_array($a)) {
$a = '[' . implode(',', $a) . ']';
}
return rawurlencode($a);
}, $args));
}

if (!empty($qs)) {
Expand Down

0 comments on commit 7f90ad8

Please sign in to comment.