Page MenuHomePhabricator

D19639.diff
No OneTemporary

D19639.diff

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 = <<<EOTEXT
+Subscribers:
+#projectname
+
+# Instructional comments.
+EOTEXT;
+
+ $expect = <<<EOTEXT
+Subscribers:
+#projectname
+
EOTEXT;
$this->assertEqual($expect, ArcanistCommentRemover::removeComments($test));

File Metadata

Mime Type
text/plain
Expires
Thu, May 9, 8:41 PM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6277066
Default Alt Text
D19639.diff (1 KB)

Event Timeline