diff --git a/src/parser/ArcanistCommentRemover.php b/src/parser/ArcanistCommentRemover.php --- a/src/parser/ArcanistCommentRemover.php +++ b/src/parser/ArcanistCommentRemover.php @@ -8,21 +8,25 @@ * considered a comment. */ public static function removeComments($body) { - $lines = explode("\n", $body); + $body = rtrim($body); + + $lines = phutil_split_lines($body); $lines = array_reverse($lines); + foreach ($lines as $key => $line) { - if (!strlen($line)) { - unset($lines[$key]); - continue; - } - if ($line[0] == '#') { + if (preg_match('/^#/', $line)) { unset($lines[$key]); continue; } + break; } + $lines = array_reverse($lines); - return implode("\n", $lines)."\n"; + $lines = implode('', $lines); + $lines = rtrim($lines)."\n"; + + return $lines; } } diff --git a/src/parser/__tests__/ArcanistCommentRemoverTestCase.php b/src/parser/__tests__/ArcanistCommentRemoverTestCase.php --- a/src/parser/__tests__/ArcanistCommentRemoverTestCase.php +++ b/src/parser/__tests__/ArcanistCommentRemoverTestCase.php @@ -24,6 +24,21 @@ The end. +EOTEXT; + + $this->assertEqual($expect, ArcanistCommentRemover::removeComments($test)); + + $test = <<assertEqual($expect, ArcanistCommentRemover::removeComments($test));