Skip to content

Instantly share code, notes, and snippets.

@piotr-cz
Last active January 2, 2016 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piotr-cz/8316210 to your computer and use it in GitHub Desktop.
Save piotr-cz/8316210 to your computer and use it in GitHub Desktop.
Joomla-CMS: JInstallerHelper::downloadPackage patch to encode url query values
/**
* JInstallerHelper::downloadPackage patch to encode redirect url query values.
*
* File Locations:
* - J3.2: /libraries/cms/installer/helper.php
* - J2.5: /libraries/joomla/installer/helper.php
*
* For performance reasons (assuming that initial $url is valid),
* this code can be moved just under the `302 == $response->code` check.
*/
public static function downloadPackage($url, $target = false)
{
/* JInstallerHelper::downloadPackage patch to encode url query values
*/
// Using JUri here (not parse_url) to preserve non-query data
$uri = new JUri($url);
// Get query variables
$vars = $uri->getQuery(true);
// Encode values
array_walk_recursive($vars, 'rawurlencode');
// Set query and convert to string
$uri->setQuery($vars);
$url = (string) $uri;
// Rest of the code
//...
}
@codeling
Copy link

codeling commented Jan 8, 2014

which version is this? J3.x? My downloadPackage (libraries/joomla/installer/helper.php, right?) in 2.5.17 looks nothing like this. Or is it just to be inserted at the beginning of the method?

@piotr-cz
Copy link
Author

piotr-cz commented Jan 8, 2014

Yeah, at the very beginning of downloadPackage method. Be warned, that I didn't test it at all.
To debug, see if this
if (strpos($url, 'https://s3.amazonaws.com/github-cloud/') === 0) { print_r($url); die('-') }} is properly escaped.

The difference is that in 3.2 helper.php is located in libraries/cms/installer and 2.5 in libraries/joomla/installer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment