Strip query strings and support download URLs in repo info parsing #5006
Content URLs drop reserved repo names
Low Severity
<!-- DESCRIPTION START -->
The _REPO_URL_SUBPATHS filter is applied when building repo_id from content/download URLs, even though _CONTENT_REPO_URL_REGEX already requires resolve, raw, or blob after the repo segments. A namespaced repo whose name is a reserved word such as settings or tree is then reported as only the namespace on download errors.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: fd1e08a4-d653-454f-b8d9-925756e46916 -->
<!-- LOCATIONS START
src/huggingface_hub/utils/_http.py#L260-L264
src/huggingface_hub/utils/_http.py#L214-L215
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
src/huggingface_hub/utils/_http.py#L214-L215</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjlkMmRkYjhmLTI0MjgtNGFhZi1hYWVmLTZhZTEzZmMzNTdiOCIsImVuY3J5cHRpb25LZXkiOiJiZkIxOUZCRVp3RzI5dGdOc0hFa3dnN01SVnltME1IMkkxOU9ySTRZOHdFIiwiYnJhbmNoIjoiZml4L2Vycm9yLXJlcG8taWQtcGFyc2luZyIsInJlcG9Pd25lciI6Imh1Z2dpbmdmYWNlIiwicmVwb05hbWUiOiJodWdnaW5nZmFjZV9odWIiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjlkMmRkYjhmLTI0MjgtNGFhZi1hYWVmLTZhZTEzZmMzNTdiOCIsImVuY3J5cHRpb25LZXkiOiJiZkIxOUZCRVp3RzI5dGdOc0hFa3dnN01SVnltME1IMkkxOU9ySTRZOHdFIiwiYnJhbmNoIjoiZml4L2Vycm9yLXJlcG8taWQtcGFyc2luZyIsInJlcG9Pd25lciI6Imh1Z2dpbmdmYWNlIiwicmVwb05hbWUiOiJodWdnaW5nZmFjZV9odWIiLCJwck51bWJlciI6NTAwNiwiY29tbWl0U2hhIjoiZjJiZDExOGVhMzcyMDJmZWRmYjU4NTc0N2ZiYjE1ZjFlODBkYTdkNSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by Cursor Bugbot for commit f2bd118ea37202fedfb585747fbb15f1e80da7d5. Configure here.</sup>
<!-- BUGBOT_REVIEW -->
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
<!-- BUGBOT_FIX_ALL -->
<a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aToxMGRhNWU3ZC05ZGRkLTRmMmEtYTUzYy1jMTRhZjQzYjI3ZTAiLCJlbmNyeXB0aW9uS2V5IjoiakkwYjlYRGdoN0pZSTh4anFBWkJkZk9QTUtKSmNLRzdWYV9PZ3VPWGowQSIsImJyYW5jaCI6ImZpeC9lcnJvci1yZXBvLWlkLXBhcnNpbmciLCJyZXBvT3duZXIiOiJodWdnaW5nZmFjZSIsInJlcG9OYW1lIjoiaHVnZ2luZ2ZhY2VfaHViIiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>
<!-- /BUGBOT_FIX_ALL -->
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN -->
<sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.</sup>
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END -->
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
<sup>Reviewed by Cursor Bugbot for commit f2bd118ea37202fedfb585747fbb15f1e80da7d5. Configure here.</sup>
Fixed in commit 4073ca5 - since content URLs explicitly require resolve/raw/blob immediately after the repo segments, any second segment is unambiguously part of the repository name (e.g. user/tree or user/settings). Added test coverage for this case as well.
Thanks fro the PR. Superseded by https://github.com/huggingface/huggingface_hub/pull/5008
bodapatisaikrishna
What does this PR do?
Fixes #5002
This PR fixes two related bugs in URL parsing for error reporting in
huggingface_hub.utils._http:1. Query strings leaking into
repo_id,bucket_id, andjob_id:_parse_repo_info_from_url,_parse_bucket_id_from_url, and_parse_job_id_from_urldid not separate the path from query parameters before matching regexes. For example:-
https://huggingface.co/api/models/user/repo?blobs=trueresulted inrepo_id="user/repo?blobs=true".-
https://huggingface.co/api/buckets/my-bucket?prefix=fooresulted inbucket_id="my-bucket?prefix=foo".Now, URLs are parsed with
urlsplit(url).pathbefore applying regex matches so query parameters are cleanly stripped.2. Download / content URLs not parsed:
_parse_repo_info_from_urlpreviously only matched/api/(models|datasets|spaces)/...endpoints. When downloading files directly from/resolve/...,/raw/..., or/blob/...(e.g., viahf downloador direct HTTP requests):-
https://huggingface.co/openai-community/gpt2/resolve/main/config.jsonreturned(None, None)-
https://huggingface.co/datasets/nyu-mll/glue/resolve/main/data.csvreturned(None, None)-
https://huggingface.co/spaces/gradio/hello_world/resolve/main/app.pyreturned(None, None)As a consequence, when a 404 or gated repo error occurred during a download,
repo_idremainedNonein the raisedHfHubHTTPError/RemoteEntryNotFoundError/GatedRepoError. For CLI commands such ashf download, this caused the error output to degrade to generic messages like"File not found in repository."without indicating which repository was being accessed.We now support model, dataset, and space download URLs with
/resolve/,/raw/, and/blob/path segments, handling both namespaced and single-segment repo IDs.3. HTTP scheme support:
Updated regex pattern from
https://tohttps?://to ensure compatibility with local test servers or custom HTTP endpoints.Tests added:
TestParseRepoInfoFromUrl:- Query parameters on API URLs (
/api/models/..., single-segment models,/api/datasets/...)- Download URLs (
/resolve/...,/raw/...,/blob/...) across models, datasets, spaces, with and without query paramsTestParseBucketIdFromUrl:- Query parameters on bucket URLs (
/api/buckets/...)<!-- CURSOR_SUMMARY -->
---
<!-- /CURSOR_SUMMARY -->