@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.

Correct a prose diff behavior when prose pieces include newlines

Summary:
See <https://discourse.phabricator-community.org/t/bad-regex-in-prose-diff-logic/3969>.

The prose splitting rules normally guarantee that newlines appear only at the beginning or end of blocks. However, if a prose sentence ends with text like "...x\n.", we can end up with a newline inside a "sentence".

If we do, the regular expression that breaks it into pieces will fail.

Arguably, this is an error in how sentences are split apart (we might prefer to split this into two sentences, "x\n" and ".", rather than a single "x\n." sentence) but in the general case it's not unreasonable for blocks to contain newlines, so a simple fix is to make the pattern more robust.

Test Plan: Added a failing test which includes this behavior, made it pass.

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

+9 -1
+1 -1
src/infrastructure/diff/prose/PhutilProseDifferenceEngine.php
··· 148 148 // whitespace at the end. 149 149 150 150 $matches = null; 151 - preg_match('/^(\s*)(.*?)(\s*)\z/', $result, $matches); 151 + preg_match('/^(\s*)(.*?)(\s*)\z/s', $result, $matches); 152 152 153 153 if (strlen($matches[1])) { 154 154 $results[] = $matches[1];
+8
src/infrastructure/diff/prose/__tests__/PhutilProseDiffTestCase.php
··· 30 30 ), 31 31 pht('Remove Paragraph')); 32 32 33 + $this->assertProseParts( 34 + 'xxx', 35 + "xxxyyy\n.zzz", 36 + array( 37 + '= xxx', 38 + "+ yyy\n.zzz", 39 + ), 40 + pht('Amend paragraph, and add paragraph starting with punctuation')); 33 41 34 42 // Without smoothing, the alogorithm identifies that "shark" and "cat" 35 43 // both contain the letter "a" and tries to express this as a very