DasIch  committed e3f214e

Fix get_ratio for empty strings

  • Participants
  • Parent commits de63799
  • Branches default

Comments (0)

Files changed (2)

File sphinx/

 from sphinx.util import PeekableIterator
+# anything below that ratio is considered equal/changed
 def add_uids(doctree, condition):
     Adds a unique id to every node in the `doctree` which matches the condition
-        if ratio < 65:
+        if ratio < VERSIONING_RATIO:
             new_node.uid = old_node.uid
             new_node.uid = uuid4().hex
     Returns a "similiarity ratio" representing the similarity between the two
     strings where 0 is equal and anything above less than equal.
+    if not all([old, new]):
+        return VERSIONING_RATIO
     return levenshtein_distance(old, new) / (len(old) / 100.0)
 def levenshtein_distance(a, b):

File tests/

 from docutils.parsers.rst.directives.html import MetaBody
 from sphinx import addnodes
-from sphinx.versioning import add_uids, merge_doctrees
+from sphinx.versioning import add_uids, merge_doctrees, get_ratio
 def setup_module():
     global app, original, original_uids
 def is_paragraph(node):
     return node.__class__.__name__ == 'paragraph'
+def test_get_ratio():
+    assert get_ratio('', 'a')
+    assert get_ratio('a', '')
 def test_add_uids():
     assert len(original_uids) == 3