From da6e82b39ab9a3bf00cd28c5559aac1594f2e42f 2012-08-05 21:51:13 From: Bradley M. Froehle Date: 2012-08-05 21:51:13 Subject: [PATCH] Fix: longest_substr([]) -> '' Previously the algorithm used to find the longest common starting substring unintentionally raised an error when it was called on an empty list. --- diff --git a/IPython/utils/tests/test_text.py b/IPython/utils/tests/test_text.py index bc795f8..a00c4a5 100644 --- a/IPython/utils/tests/test_text.py +++ b/IPython/utils/tests/test_text.py @@ -149,6 +149,9 @@ def test_long_substr2(): data = ['abc', 'abd', 'abf', 'ab'] nt.assert_equal(text.long_substr(data), 'ab') +def test_long_substr_empty(): + data = [] + nt.assert_equal(text.long_substr(data), '') def test_strip_email(): src = """\ diff --git a/IPython/utils/text.py b/IPython/utils/text.py index f66962a..b53f826 100644 --- a/IPython/utils/text.py +++ b/IPython/utils/text.py @@ -553,7 +553,7 @@ def long_substr(data): for j in range(len(data[0])-i+1): if j > len(substr) and all(data[0][i:i+j] in x for x in data): substr = data[0][i:i+j] - else: + elif len(data) == 1: substr = data[0] return substr