Repository: jaraco/inflect

Issue:
number_to_words crashes on strings 'st', 'nd' etc
Calling number_to_words on strings like 'st', 'nd' crashes. This is because of this line: https://github.com/jaraco/inflect/blob/98e19e3eb3ad28f9fa882baaad01674c44b59952/inflect.py#L3711 making the num variable empty and this line https://github.com/jaraco/inflect/blob/98e19e3eb3ad28f9fa882baaad01674c44b59952/inflect.py#L3727 indexing the empty resulting array.

Discussion:

Patch:
diff --git a/inflect.py b/inflect.py
index 3bb946b..de2fc5a 100644
--- a/inflect.py
+++ b/inflect.py
@@ -1848,6 +1848,7 @@ nth = {
     12: "th",
     13: "th",
 }
+nth_suff = set(nth.values())
 
 ordinal = dict(
     ty="tieth",
@@ -3706,7 +3707,10 @@ class engine:
         else:
             sign = ""
 
-        myord = num[-2:] in ("st", "nd", "rd", "th")
+        if num in nth_suff:
+            num = zero
+
+        myord = num[-2:] in nth_suff
         if myord:
             num = num[:-2]
         finalpoint = False


Test patch:
diff --git a/tests/test_numwords.py b/tests/test_numwords.py
index 1707400..042b45a 100644
--- a/tests/test_numwords.py
+++ b/tests/test_numwords.py
@@ -391,3 +391,9 @@ def go(p, i):
 
     # eq_ !eval { p.number_to_words(42, and=>); 1; };
     # eq_ $@ =~ 'odd number of';
+
+
+def test_issue_131():
+    p = inflect.engine()
+    for nth_word in inflect.nth_suff:
+        assert p.number_to_words(nth_word) == "zero"