From a89d65afc67537ba3ab1024ed45da891176068da Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Mon, 16 Jan 2012 15:05:35 +0100 Subject: [PATCH] appy.shared.diff: bugfixes. --- shared/diff.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shared/diff.py b/shared/diff.py index e688bf8..e5be6b5 100644 --- a/shared/diff.py +++ b/shared/diff.py @@ -333,6 +333,9 @@ class HtmlDiff: def isSimilar(self, s1, s2): '''Returns True if strings p_s1 and p_s2 can be considered as similar.''' + # Bypass the similarity algorithm for strings of length==1. Else, it can + # lead to infinite loops between methods getHtmlDiff and getReplacement. + if (len(s1) == 1) and (len(s2) == 1) and (s1 != s2): return False ratio = difflib.SequenceMatcher(a=s1.lower(), b=s2.lower()).ratio() return ratio > self.diffRatio @@ -487,7 +490,7 @@ class HtmlDiff: i = len(l)-1 while i >= 0: if l[i] in self.garbage: del l[i] - if sep == '\n': l[i] = l[i].strip() + elif sep == '\n': l[i] = l[i].strip() i -= 1 return l