Bladeren bron

Fix issue 44: unexpected side-by-side output for diff of diff

Common error of using lstrip:

 lstrip('\x00+') will eat all '+' after '\x00'
Matthew Wang 9 jaren geleden
bovenliggende
commit
10fa1e838a
1 gewijzigde bestanden met toevoegingen van 6 en 2 verwijderingen
  1. 6
    2
      cdiff.py

+ 6
- 2
cdiff.py Bestand weergeven

@@ -547,11 +547,15 @@ class DiffMarker(object):
547 547
                 if changed:
548 548
                     if not old[0]:
549 549
                         left = '%*s' % (width, ' ')
550
-                        right = right.lstrip('\x00+').rstrip('\x01')
550
+                        right = right.rstrip('\x01')
551
+                        if right.startswith('\x00+'):
552
+                            right = right[2:]
551 553
                         right = _fit_with_marker(
552 554
                             right, self._markup_new, width)
553 555
                     elif not new[0]:
554
-                        left = left.lstrip('\x00-').rstrip('\x01')
556
+                        left = left.rstrip('\x01')
557
+                        if left.startswith('\x00-'):
558
+                            left = left[2:]
555 559
                         left = _fit_with_marker(left, self._markup_old, width)
556 560
                         right = ''
557 561
                     else: