Repository: facelessuser/soupsieve

Issue:
:nth-of-type and :nth-child works only up to the 9th element
Not sure where to file this bug as I'm using soupsieve via BeautifulSoup4, but here goes:

Using BeautifulSoup4 4.7.1, with SoupSieve 1.6.2, under Python 3.6.

```py
import bs4

source = """<html><body>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
</body></html>"""
soup = bs4.BeautifulSoup(source, 'lxml')  # same result with html5lib

print(soup.select("div:nth-of-type(9)"))  # Expect 9, is 9
print(soup.select("div:nth-child(9)"))  # Expect 9, is 9
print(soup.select("div:nth-of-type(10)"))  # Expect 10, is 15
print(soup.select("div:nth-child(10)"))  # Expect 10, is 15
print(soup.select("div:nth-of-type(11)"))  # Expect 11, is 16
print(soup.select("div:nth-child(11)"))  # Expect 11, is 16
print(soup.select("div:nth-of-type(12)"))  # Expect 12, finds nothing
print(soup.select("div:nth-child(12)"))  # Expect 12, finds nothing
```

It seems to work well with single-digit index, but either returns empty or the wrong element for 10 and upwards.

(Also filed this on BS4 LaunchPad.)

Discussion:

Patch:
diff --git a/docs/src/markdown/about/changelog.md b/docs/src/markdown/about/changelog.md
index 02a0f15..11876ad 100644
--- a/docs/src/markdown/about/changelog.md
+++ b/docs/src/markdown/about/changelog.md
@@ -9,6 +9,7 @@
   some exceptions. (#72, #73)
 - **FIX**: Don't compare prefixes when evaluating attribute namespaces, compare the actual namespace. (#75)
 - **FIX**: Split whitespace attribute lists by all whitespace characters, not just space.
+- **FIX**: `:nth-*` patterns were converting numbers to base 16 when they should have been converting to base 10.
 
 ## 1.6.2
 
diff --git a/soupsieve/css_parser.py b/soupsieve/css_parser.py
index c41ce7e..ac1a2cd 100644
--- a/soupsieve/css_parser.py
+++ b/soupsieve/css_parser.py
@@ -518,8 +518,8 @@ class CSSParser(object):
                 s2 += nth_parts.group('b')
             else:
                 s2 = '0'
-            s1 = int(s1, 16)
-            s2 = int(s2, 16)
+            s1 = int(s1, 10)
+            s2 = int(s2, 10)
 
         pseudo_sel = util.lower(m.group('pseudo_nth' + postfix))
         if postfix == '_child':


Test patch:
diff --git a/tests/test_level3.py b/tests/test_level3.py
index a533043..b8c4ba9 100644
--- a/tests/test_level3.py
+++ b/tests/test_level3.py
@@ -891,6 +891,57 @@ class TestLevel3(util.TestCase):
         fragment = soup.p.extract()
         self.assertTrue(sv.match("p:nth-child(1)", fragment, flags=sv.DEBUG))
 
+    def test_nth_child_issue_78(self):
+        """Test issue for https://github.com/facelessuser/soupsieve/issues/78."""
+
+        markup = """<html><body>
+        <div id= "1">1</div>
+        <div id= "2">2</div>
+        <div id= "3">3</div>
+        <div id= "4">4</div>
+        <div id= "5">5</div>
+        <div id= "6">6</div>
+        <div id= "7">7</div>
+        <div id= "8">8</div>
+        <div id= "9">9</div>
+        <div id= "10">10</div>
+        <div id= "11">11</div>
+        <div id= "12">12</div>
+        <div id= "13">13</div>
+        <div id= "14">14</div>
+        <div id= "15">15</div>
+        <div id= "16">16</div>
+        <div id= "17">17</div>
+        </body></html>"""
+
+        self.assert_selector(
+            markup,
+            "div:nth-of-type(10)",
+            ['10'],
+            flags=util.XML
+        )
+
+        self.assert_selector(
+            markup,
+            "div:nth-child(10)",
+            ['10'],
+            flags=util.XML
+        )
+
+        self.assert_selector(
+            markup,
+            "div:nth-of-type(n+10)",
+            ['10', '11', '12', '13', '14', '15', '16', '17'],
+            flags=util.XML
+        )
+
+        self.assert_selector(
+            markup,
+            "div:nth-of-type(n+10)",
+            ['10', '11', '12', '13', '14', '15', '16', '17'],
+            flags=util.XML
+        )
+
     def test_nth_last_child(self):
         """Test `nth` last child."""