Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong indices and repeated matches when hostname contains the TLD #155

Open
carton-of-mice opened this issue Nov 15, 2023 · 0 comments
Open

Comments

@carton-of-mice
Copy link

Although In gen_urls() a call to _get_tld_pos() determines the correct position of the TLD using rfind(), this correction has no bearing on on tld_pos, leading to returned incorrect indices and an invalid offset on the next loop..
Should the same TLD appear multiple times within a hostname, it may match repeatedly.
For example

>>> txt = "String bbb.aaa.bbb.aaa.aaa test string"
>>> for out in urlextract.URLExtract().gen_urls(txt, get_indices=1):
...     print(out, txt[out[1][0] : out[1][1]])
...
('bbb.aaa.bbb.aaa.aaa', (-5, 14))
('bbb.aaa.bbb.aaa.aaa', (3, 22)) ing bbb.aaa.bbb.aaa
('bbb.aaa.bbb.aaa.aaa', (7, 26)) bbb.aaa.bbb.aaa.aaa

Should there be a query part in the string, further matches will possibly be skipped.

>>> txt = "String http://bbb.aaa.aaa/tests test string"
>>> for out in urlextract.URLExtract().gen_urls(txt, get_indices=1):
...     print(out, txt[out[1][0] : out[1][1]])
...
('http://bbb.aaa.aaa/tests', (3, 27)) ing http://bbb.aaa.aaa/t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant