Repository navigation
Conversation
gen_urls() located the matched TLD in the extracted URL with _get_tld_pos(), which returns the last TLD of the hostname. When the hostname contains the TLD more than once (e.g. my.example.com.example.com) and the first occurrence was matched, the cursor was not moved past the URL. The URL was then returned again for every following TLD match, with wrong (even negative) indices. Use the position of the matched TLD in the text to find where it sits inside the extracted URL. Fixes lipoja#155
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #155
When a hostname contains the TLD more than once, the first match can be one in the middle of the hostname, e.g. the first
.cominmy.example.com.example.com.gen_urls()then looked the TLD up in the extracted URL with_get_tld_pos(), which returns the last TLD of the hostname. Because of that, the cursor never moved past the URL: the same URL came back again for every later TLD match, and the indices were wrong (sometimes negative).This PR adds
_get_matched_tld_pos(). It uses the position of the matched TLD in the text to work out where that TLD sits in the extracted URL. If the URL can't be found around the match, it falls back to_get_tld_pos().Before:
After:
Tests: I added cases to
tests/unit/test_find_urls.py(3 fail on master, pass with the fix).pytest --ignore setup.py: 185 passedpytest urlextract --doctest-modules: passesblack --check --skip-string-normalizationandflake8: cleanmypy: same 5 errors as on master, none in the changed code