From 8bf31a1e553e1cca5ad98c60fa8725d63f40902a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ebbrecht?= Date: Wed, 29 Apr 2015 22:29:00 +0200 Subject: [PATCH] fixed issue #584, improved download name for zip/tarballs --- src/GitList/Controller/TreeController.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/GitList/Controller/TreeController.php b/src/GitList/Controller/TreeController.php index 1f20220..58eaec4 100644 --- a/src/GitList/Controller/TreeController.php +++ b/src/GitList/Controller/TreeController.php @@ -87,13 +87,24 @@ class TreeController implements ControllerProviderInterface . substr($tree, 0, 2) . DIRECTORY_SEPARATOR . substr($tree, 2) . '.' - . $format; + . $format; if (!file_exists($file)) { $repository->createArchive($tree, $file, $format); } - return new BinaryFileResponse($file); + /** + * Generating name for downloading, lowercasing and removing all non + * ascii and special characters + */ + $filename = strtolower($branch); + $filename = preg_replace('#[^a-z0-9]#', '_', $filename); + $filename = preg_replace('#_+#', '_', $filename); + $filename = $filename . '.' . $format; + + $response = new BinaryFileResponse($file); + $response->setContentDisposition('attachment', $filename); + return $response; })->assert('format', '(zip|tar)') ->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', $app['util.routing']->getBranchRegex())