Repository: lipoja/URLExtract

Issue:
Wrong indices with uppercase characters in domain name
I am getting wrong indices when the domain name of a URL contains uppercase characters.

To reproduce:
```
from urlextract import URLExtract
extractor = URLExtract()
urls = extractor.find_urls("www.Google.com", get_indices=True)
print(urls[0])
urls = extractor.find_urls("www.google.com", get_indices=True)
print(urls[0])
```
Output is:
```
('www.Google.com', (1, 15))
('www.google.com', (0, 14))
```


Discussion:
lipoja: @iwangpeng Thank you for this PR! It is nice catch! 
May I ask you to add unit tests so we would prevent regressions? Once it is done I will merge it!

Thank you!
lipoja: @iwangpeng Thank you for your time and this PR! 

Patch:
diff --git a/urlextract/urlextract_core.py b/urlextract/urlextract_core.py
index b6b3767..8283024 100644
--- a/urlextract/urlextract_core.py
+++ b/urlextract/urlextract_core.py
@@ -760,8 +760,11 @@ class URLExtract(CacheFile):
 
         url_parts = uritools.urisplit(tpm_url)
         host = str(url_parts.gethost())
-        offset = url.find(host)
-        return host.rfind(tld) + offset
+        # `host` is always returned in lowercase,
+        # so make sure `url` & `tld` must also be lowercase,
+        # otherwise the `find()` may fail.
+        offset = url.lower().find(host)
+        return host.rfind(tld.lower()) + offset
 
     # TODO: move type assertion to be Generator based
     # found https://stackoverflow.com/a/38423388/14669675


Test patch:
diff --git a/tests/unit/test_find_urls.py b/tests/unit/test_find_urls.py
index 90250e6..9ee46eb 100644
--- a/tests/unit/test_find_urls.py
+++ b/tests/unit/test_find_urls.py
@@ -112,10 +112,10 @@ def test_find_urls_unique(urlextract, text, expected):
     "text, expected",
     [
         (
-            "Let's have URL http://janlipovsky.cz and a second URL https://example.com/@eon01/asdsd-dummy it's over.",
+            "Let's have URL http://janlipovsky.cz and a second URL https://Example.Com/@eon01/asdsd-dummy it's over.",
             [
                 ("http://janlipovsky.cz", (15, 36)),
-                ("https://example.com/@eon01/asdsd-dummy", (54, 92)),
+                ("https://Example.Com/@eon01/asdsd-dummy", (54, 92)),
             ],
         ),
         (
diff --git a/tests/unit/test_get_tld_pos.py b/tests/unit/test_get_tld_pos.py
new file mode 100644
index 0000000..64997cd
--- /dev/null
+++ b/tests/unit/test_get_tld_pos.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+This file contains pytests for _get_tld_pos() method of URLExtract
+
+.. Licence MIT
+.. codeauthor:: Jan Lipovský <janlipovsky@gmail.com>, janlipovsky.cz
+"""
+import pytest
+
+
+@pytest.mark.parametrize(
+    "url, tld, expected",
+    [
+        ("httpbin.org/status/200", ".org", 7),
+        ("https://httpbin.org/status/200", ".org", 15),
+        ("caseInsensitive.cOM", ".cOM", 15),
+        ("https://caseInsensitive.COM/status/200", ".COM", 23),
+    ],
+)
+def test_get_ltd_pos(urlextract, url, tld, expected):
+    """
+    Testing _get_tld_pos returning index
+
+    :param fixture urlextract: fixture holding URLExtract object
+    :param str url: URL in which tld should be located
+    :param str tld: TLD we want to find
+    :param int expected: index of tld that has be found in url
+    """
+    assert urlextract._get_tld_pos(url, tld) == expected