Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15393308
D8968.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D8968.diff
View Options
diff --git a/src/applications/differential/parser/DifferentialHunkParser.php b/src/applications/differential/parser/DifferentialHunkParser.php
--- a/src/applications/differential/parser/DifferentialHunkParser.php
+++ b/src/applications/differential/parser/DifferentialHunkParser.php
@@ -423,16 +423,41 @@
$lines = phutil_split_lines($lines);
$line_type_map = array();
+ $line_text = array();
foreach ($lines as $line_index => $line) {
if (isset($line[0])) {
$char = $line[0];
- if ($char == ' ') {
- $line_type_map[$line_index] = null;
- } else {
- $line_type_map[$line_index] = $char;
+ switch ($char) {
+ case " ":
+ $line_type_map[$line_index] = null;
+ $line_text[$line_index] = substr($line, 1);
+ break;
+ case "\r":
+ case "\n":
+ // NOTE: Normally, the first character is a space, plus, minus or
+ // backslash, but it may be a newline if it used to be a space and
+ // trailing whitespace has been stripped via email transmission or
+ // some similar mechanism. In these cases, we essentially pretend
+ // the missing space is still there.
+ $line_type_map[$line_index] = null;
+ $line_text[$line_index] = $line;
+ break;
+ case "+":
+ case "-":
+ case "\\":
+ $line_type_map[$line_index] = $char;
+ $line_text[$line_index] = substr($line, 1);
+ break;
+ default:
+ throw new Exception(
+ pht(
+ 'Unexpected leading character "%s" at line index %s!',
+ $char,
+ $line_index));
}
} else {
$line_type_map[$line_index] = null;
+ $line_text[$line_index] = '';
}
}
@@ -444,7 +469,7 @@
$type = $line_type_map[$cursor];
$data = array(
'type' => $type,
- 'text' => (string)substr($lines[$cursor], 1),
+ 'text' => $line_text[$cursor],
'line' => $new_line,
);
if ($type == '\\') {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 16, 8:47 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7321410
Default Alt Text
D8968.diff (2 KB)
Attached To
Mode
D8968: Fix two parsing issues for diffs with damaged whitespace
Attached
Detach File
Event Timeline
Log In to Comment