Fix _is_nonsense_url dropping trailing-slash language roots (/en/)#2035
Open
jichaowang02-lang wants to merge 1 commit into
Open
Conversation
The "very short path" filter measured length on the slash-stripped path
(`len(path.strip('/')) < 3`) but matched the *un-stripped* path against the
language-root whitelist (`path not in ['/', '/en', ...]`). So the canonical
trailing-slash form of a language root — `/en/`, `/de/`, `/fr/`, `/es/`,
`/it/`, which is what sitemaps and urljoin normalization commonly emit — was
filtered out as nonsense, even though `/en` was correctly kept. With
filter_nonsense_urls on (the default), these valid localized landing pages
were silently dropped from seeding results.
Compare the slash-stripped path against the whitelist as well, so a language
root is kept regardless of a trailing slash; genuinely short junk paths
(`/ab/`, `/x`) are still filtered.
Adds tests/unit/test_nonsense_url_language_roots.py; the trailing-slash cases
fail on the old code and pass with this fix.
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.
Summary
AsyncUrlSeeder._is_nonsense_urlfilters "very short paths", but the check is inconsistent:The length test strips slashes (
path.strip('/')), but the whitelist membership uses the un-strippedpath(which keeps trailing slashes). So the canonical trailing-slash form of a language root is dropped as nonsense:/en/en//de/,/fr/,/es/,/it//ab/,/x(real junk)Trailing slashes are the conventional directory form emitted by sitemaps and by
urljoinnormalization, so withfilter_nonsense_urlsenabled (the default) legitimate localized landing pages (/en/,/de/, …) were silently discarded from seeding results.Fix
Compare the slash-stripped path against the whitelist too, so a language root is kept with or without a trailing slash. Genuinely short non-language paths are still filtered.
Testing
Adds
tests/unit/test_nonsense_url_language_roots.py; the trailing-slash language-root cases fail on the current code (5 failed) and pass with this fix, while short-junk/utility URLs stay filtered.