From 8c141fdfd1bf6a53a7de0ba8be5027886cdeac48 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 19 Mar 2012 19:17:50 -0700 Subject: [PATCH] Fix an issue where DiffusionGitBrowseQuery incorrectly parses filenames with spaces Summary: Split from D1921. We'll explode each line into too many parts currently, if the filename contains spaces. Also use -z to get \0 newlines. Test Plan: Browsed a directory containing files with spaces in their names, links etc were correct. Reviewers: nh, vrana, btrahan Reviewed By: btrahan CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D1924 --- .../query/browse/git/DiffusionGitBrowseQuery.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/applications/diffusion/query/browse/git/DiffusionGitBrowseQuery.php b/src/applications/diffusion/query/browse/git/DiffusionGitBrowseQuery.php index 973ae4a916..ad60353f33 100644 --- a/src/applications/diffusion/query/browse/git/DiffusionGitBrowseQuery.php +++ b/src/applications/diffusion/query/browse/git/DiffusionGitBrowseQuery.php @@ -1,7 +1,7 @@ execxLocalCommand( - 'ls-tree -l %s:%s', + 'ls-tree -z -l %s:%s', $commit, $path); $results = array(); - foreach (explode("\n", rtrim($stdout)) as $line) { - list($mode, $type, $hash, $size, $name) = preg_split('/\s+/', $line); + foreach (explode("\0", rtrim($stdout)) as $line) { + // NOTE: Limit to 5 components so we parse filenames with spaces in them + // correctly. + list($mode, $type, $hash, $size, $name) = preg_split('/\s+/', $line, 5); if ($type == 'tree') { $file_type = DifferentialChangeType::FILE_DIRECTORY; } else {