From 1095e509dee7c326e6c1b330b3c69ddcf55f0651 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 3 May 2008 07:40:46 +0000 Subject: [PATCH] Fixed yet another diff-breaking edge case. This one had to do with inserting italicized text right before some existing italicized text. --- NEWS | 4 ++++ controller/Html_differ.py | 5 +++++ controller/test/Test_html_differ.py | 30 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/NEWS b/NEWS index f1fa141..52a19e1 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +1.3.12: May 3, 2008: + * Fixed yet another diff-breaking edge case. This one had to do with + inserting italicized text right before some existing italicized text. + 1.3.11: May 2, 2008 * Fixed another bug that prevented diffs from working. This time, those with
tags didn't parse correctly. diff --git a/controller/Html_differ.py b/controller/Html_differ.py index 01d84eb..b735598 100644 --- a/controller/Html_differ.py +++ b/controller/Html_differ.py @@ -182,6 +182,11 @@ class Html_differ( HTMLParser ): open_del_items = [] open_ins_items = [] + if len( open_del_items ): + result_a.extend( open_del_items ) + if len( open_ins_items ): + result_b.extend( open_ins_items ) + return ( result_a, result_b ) def diff_lists( self, a, b ): diff --git a/controller/test/Test_html_differ.py b/controller/test/Test_html_differ.py index 455e953..647e7b6 100644 --- a/controller/test/Test_html_differ.py +++ b/controller/test/Test_html_differ.py @@ -75,6 +75,15 @@ class Test_html_differ( object ): assert result == 'foo bar baz bar whee baz quux' + def test_diff_with_italics_twice( self ): + a = 'foo bar baz quux foo' + b = 'foo bar baz quux wheefoo' + + result = self.differ.diff( a, b ) + + # note the screwy placement of the tags. this is the best the differ can do for now + assert result == 'foo bar baz quux wheefoo' + def test_diff_with_link( self ): a = 'foo bar baz quux' b = 'foo bar baz quux' @@ -181,6 +190,19 @@ class Test_html_differ( object ): assert new_a == [ 'foo ', 'bar baz ', 'quux' ] assert new_b == [ 'foo ', 'bar whee baz ', 'quux' ] + def test_prepare_lists_with_italics_twice( self ): + a = [ 'foo ', 'bar ', 'baz ', 'quux ', '', 'foo', '' ] + b = [ 'foo ', 'bar ', 'baz ', 'quux ', '', 'whee', '', '', 'foo', '' ] + + result = self.differ.prepare_lists( a, b ) + + assert len( result ) == 2 + ( new_a, new_b ) = result + + # there should be no change, because prepare_lists() doesn't know how to merge a complex case like this + assert new_a == a + assert new_b == b + def test_prepare_lists_with_link( self ): a = [ 'foo ', 'bar ', 'baz ', 'quux' ] b = [ 'foo ', '', 'bar ', 'baz', ' ', 'quux' ] @@ -247,6 +269,14 @@ class Test_html_differ( object ): assert result == 'foo bar baz bar whee baz quux' + def test_diff_lists_with_italics_twice( self ): + a = [ 'foo ', 'bar ', 'baz ', 'quux ', 'foo' ] + b = [ 'foo ', 'bar ', 'baz ', 'quux ', 'whee', 'foo' ] + + result = self.differ.diff_lists( a, b ) + + assert result == 'foo bar baz quux wheefoo' + def test_diff_lists_with_link( self ): a = [ 'foo ', 'bar baz ', 'quux' ] b = [ 'foo ', 'bar baz ', 'quux' ]