From 46f4f6cf0acb14c4705878c7a66a8ff46517708f Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 16 Aug 2012 12:48:37 -0700 Subject: [PATCH] Fix a fatal if a directory listing contains a non-file called 'readme' Summary: See T1665. If you have a directory named 'readme', we try to read it as a README. Test Plan: Created a directory named 'readme', hit a similar fatal to the one in T1665, applied this patch, everything worked great. Reviewers: btrahan, vrana Reviewed By: vrana CC: aran Maniphest Tasks: T1665 Differential Revision: https://secure.phabricator.com/D3312 --- .../diffusion/query/browse/DiffusionBrowseQuery.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/applications/diffusion/query/browse/DiffusionBrowseQuery.php b/src/applications/diffusion/query/browse/DiffusionBrowseQuery.php index 675623e663..5240d031a4 100644 --- a/src/applications/diffusion/query/browse/DiffusionBrowseQuery.php +++ b/src/applications/diffusion/query/browse/DiffusionBrowseQuery.php @@ -95,7 +95,15 @@ abstract class DiffusionBrowseQuery { $readme = null; foreach ($results as $result) { + $file_type = $result->getFileType(); + if (($file_type != ArcanistDiffChangeType::FILE_NORMAL) && + ($file_type != ArcanistDiffChangeType::FILE_TEXT)) { + // Skip directories, etc. + continue; + } + $path = $result->getPath(); + if (preg_match('/^readme(|\.txt|\.remarkup|\.rainbow)$/i', $path)) { $readme = $result; break; @@ -118,7 +126,6 @@ abstract class DiffusionBrowseQuery { $content_query->loadFileContent(); $readme_content = $content_query->getRawData(); - if (preg_match('/\\.txt$/', $readme->getPath())) { $readme_content = phutil_escape_html($readme_content); $readme_content = nl2br($readme_content);