[meld] Check for empty line sequences when looking for common prefix/suffix



commit 5bac4aa16d932189d738a93b92fb146ba1daf6d6
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Wed Oct 6 07:26:27 2010 +1000

    Check for empty line sequences when looking for common prefix/suffix
    
    This case can occur in a variety of situations, but specifically happens
    when we use splitlines() instead of split('\n'), changing last-line
    behaviour.

 meld/matchers.py |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
---
diff --git a/meld/matchers.py b/meld/matchers.py
index f9ed34d..5393de0 100644
--- a/meld/matchers.py
+++ b/meld/matchers.py
@@ -18,6 +18,8 @@ import difflib
 
 
 def find_common_prefix(a, b):
+    if not a or not b:
+        return 0
     if a[0] == b[0]:
         pointermax = min(len(a), len(b))
         pointermid = pointermax
@@ -33,6 +35,8 @@ def find_common_prefix(a, b):
 
 
 def find_common_suffix(a, b):
+    if not a or not b:
+        return 0
     if a[-1] == b[-1]:
         pointermax = min(len(a), len(b))
         pointermid = pointermax



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]