Skip to content

Commit

Permalink
Backport PR #2261: Fix: longest_substr([]) -> ''
Browse files Browse the repository at this point in the history
Previously the algorithm used to find the longest common starting substring
unintentionally raised an error when it was called on an empty list.

This should fix the issue of an error being raised when running %paste
on an empty clipboard (#2252).
  • Loading branch information
minrk committed Sep 1, 2012
1 parent 8f3a62b commit c166aa0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions IPython/utils/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ def test_long_substr2():
data = ['abc', 'abd', 'abf', 'ab']
nt.assert_equals(text.long_substr(data), 'ab')

def test_long_substr_empty():
data = []
nt.assert_equals(text.long_substr(data), '')

def test_strip_email():
src = """\
Expand Down
2 changes: 1 addition & 1 deletion IPython/utils/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c166aa0

Please sign in to comment.