@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix two parsing issues for diffs with damaged whitespace

Summary:
Fixes T4941. If a diff has had trailing whitespace stripped, we will fail to handle empty lines correctly (previously, these lines had a leading space when the original tool emitted them).

(This probably stopped working around the time we began retaining newlines.)

Test Plan: The diff in T4941 now parses and renders correctly.

Reviewers: asherkin, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4941

Differential Revision: https://secure.phabricator.com/D8968

+30 -5
+30 -5
src/applications/differential/parser/DifferentialHunkParser.php
··· 423 423 $lines = phutil_split_lines($lines); 424 424 425 425 $line_type_map = array(); 426 + $line_text = array(); 426 427 foreach ($lines as $line_index => $line) { 427 428 if (isset($line[0])) { 428 429 $char = $line[0]; 429 - if ($char == ' ') { 430 - $line_type_map[$line_index] = null; 431 - } else { 432 - $line_type_map[$line_index] = $char; 430 + switch ($char) { 431 + case " ": 432 + $line_type_map[$line_index] = null; 433 + $line_text[$line_index] = substr($line, 1); 434 + break; 435 + case "\r": 436 + case "\n": 437 + // NOTE: Normally, the first character is a space, plus, minus or 438 + // backslash, but it may be a newline if it used to be a space and 439 + // trailing whitespace has been stripped via email transmission or 440 + // some similar mechanism. In these cases, we essentially pretend 441 + // the missing space is still there. 442 + $line_type_map[$line_index] = null; 443 + $line_text[$line_index] = $line; 444 + break; 445 + case "+": 446 + case "-": 447 + case "\\": 448 + $line_type_map[$line_index] = $char; 449 + $line_text[$line_index] = substr($line, 1); 450 + break; 451 + default: 452 + throw new Exception( 453 + pht( 454 + 'Unexpected leading character "%s" at line index %s!', 455 + $char, 456 + $line_index)); 433 457 } 434 458 } else { 435 459 $line_type_map[$line_index] = null; 460 + $line_text[$line_index] = ''; 436 461 } 437 462 } 438 463 ··· 444 469 $type = $line_type_map[$cursor]; 445 470 $data = array( 446 471 'type' => $type, 447 - 'text' => (string)substr($lines[$cursor], 1), 472 + 'text' => $line_text[$cursor], 448 473 'line' => $new_line, 449 474 ); 450 475 if ($type == '\\') {