Skip to content
Browse files

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.
  • Loading branch information...
1 parent 8be0112 commit da6e82b39ab9a3bf00cd28c5559aac1594f2e42f @bfroehle committed Aug 5, 2012
Showing with 4 additions and 1 deletion.
  1. +3 −0 IPython/utils/tests/test_text.py
  2. +1 −1 IPython/utils/text.py
View
3 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 = """\
View
2 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

0 comments on commit da6e82b

Please sign in to comment.
Something went wrong with that request. Please try again.