From a3cada98079e3de205a1122565e96f8cd790d9ce Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Fri, 28 May 2010 19:17:47 -0700 Subject: [PATCH] void divide-by-zero when comparing two zero-length strings (!!! problem) --- beets/autotag/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index ef1474948..eb8e03049 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -90,6 +90,10 @@ def _ie_dist(str1, str2): str1 = re.sub(r'[^a-z0-9]', '', str1.lower()) str2 = re.sub(r'[^a-z0-9]', '', str2.lower()) + # Avoid divide-by-zero. Two emptry strings are identical. + if not str1 and not str2: + return 0 + # Here's a nice DP edit distance implementation from Wikibooks: # http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/ # Levenshtein_distance#Python