Repository navigation
grass.utils: Fix the download error message and limit the URL schemes - #7687
Merged
Merged
Conversation
The message is a copy of the one in g.extension.all, but it lost the {desc}
placeholder, so it ended with a dangling comma, and it was formatted with the
whole HTTPError object instead of a status code:
Download file from <URL>, return status code HTTP Error 404: Not Found,
Pass the status code and its description, which restores the message as it is
used elsewhere and keeps its existing translations:
Download file from <URL>, return status code 404, Not Found
The ZIP and TAR branches handled the errors of the download itself in the same
way, so move the download to a function. Chain the original exception to keep
its details available.
echoix
previously approved these changes
Jul 13, 2026
urlretrieve opens whatever scheme it is given, including the data scheme and any scheme added by a custom URL opener. Check the scheme against the ones which are supported before the download. A path without a scheme is not a URL and failed with an unhandled ValueError from urlretrieve, and a Windows path was reported as a failed connection. Both are now reported as an unsupported URL. An archive on the local disk works only with the file scheme, so say that in the documentation of g.download.project instead of just mentioning a local file.
Cover the extraction of a ZIP and a TAR archive from the local disk and the rejection of an unsupported URL scheme. There were no tests for the module.
cwhite911
previously approved these changes
Jul 14, 2026
echoix
previously approved these changes
Jul 14, 2026
Member
|
It seems on windows there isn’t a zip file for the test? Or the zip file isn’t an archive? Was it written as a text file instead of bytes, such as the zip contents pass through the encoding mechanisms? |
For a file URL there is no server response, so urlretrieve synthesizes the content type from the file name. On Windows the registry maps .zip to application/x-zip-compressed, which the check does not accept, so extracting a local ZIP failed there. Skip the check for the file scheme; a local file which is not a ZIP is still caught by extract_zip.
cwhite911
approved these changes
Jul 15, 2026
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.
A failed download was reported with a message copied from g.extension.all which lost its
{desc}placeholder, so it ended with a dangling comma and was formatted with the wholeHTTPErrorobject instead of a status code:It now passes the status code and its description, which restores the message as it is used elsewhere, so the msgid and its translations stay valid:
The identical error handling of the ZIP and TAR branches moves to a
_download_file()function and the original exception is chained.The URL scheme is now checked against the supported ones (
http,https,ftp,file), becauseurlretrieveopens any scheme it is given (Bandit B310). Every scheme which works today keeps working. An archive on the local disk works only asfile://(a plain path failed with an unhandledValueError), so the g.download.project documentation now says that.The module had no tests. The new ones extract a ZIP and a TAR archive from the local disk and check that an unsupported scheme is rejected.
Note: this touches the same lines as #4032, so whichever is merged second needs a trivial conflict resolution.
Commit message
Fix the HTTP error message, which lost its {desc} placeholder and was
formatted with the whole HTTPError instead of a status code. Limit a download
to the supported schemes (http, https, ftp, file), since urlretrieve opens
any scheme, including data and custom ones (Bandit B310), and document that a
local archive needs the file scheme (no change in behavior, just doc clarity).
Skip the content type check for a local file, which fixed extracting a local ZIP
on Windows. Add tests for the module.