]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Disable intraline diff highlighting algorithm for lines which contain UTF-8 text
authorepriestley <git@epriestley.com>
Fri, 24 Jun 2011 17:11:43 +0000 (10:11 -0700)
committerepriestley <git@epriestley.com>
Sun, 26 Jun 2011 18:55:30 +0000 (11:55 -0700)
Summary: This is sort of cheating, but just have this feature disable itself if the input contains multibyte UTF-8 characters. We can clean it up in the future, maybe when we have better utf8 tools.

This means that all the algorithms are safe to pass utf8 to, so we can get rid of all the "<?>" silliness.

Test Plan: Added a UTF8 character to a line, diffed it out, and got the entire line highlighted as changed. See: https://secure.phabricator.com/file/view/PHID-FILE-70fb54eb3f88dc057ab3/

Reviewers: jungejason, aran, tuomaspelkonen

CC:

Differential Revision: 514

src/difference/ArcanistDiffUtils.php

index e1534cfba98c8495be7bd5a2184689afcffc3a42..9949d4648cb35e337881461c500390b148f5f0d3 100644 (file)
@@ -55,6 +55,16 @@ final class ArcanistDiffUtils {
       );
     }
 
+    // This algorithm is byte-oriented and thus not safe for UTF-8, so just
+    // mark all the text as changed if either string has multibyte characters
+    // in it. TODO: Fix this so that this algorithm is UTF-8 aware.
+    if (preg_match('/[\x80-\xFF]/', $o.$n)) {
+      return array(
+        array(array(1, strlen($o))),
+        array(array(1, strlen($n))),
+      );
+    }
+
     $result = self::buildLevenshteinDifferenceString($o, $n);
 
     do {