This repository was archived by the owner on Mar 26, 2026. It is now read-only.
fix(image): Correctly handle query parameters in image URL validation#1288
Open
devsymo wants to merge 1 commit intoharvester:masterfrom
Open
fix(image): Correctly handle query parameters in image URL validation#1288devsymo wants to merge 1 commit intoharvester:masterfrom
devsymo wants to merge 1 commit intoharvester:masterfrom
Conversation
The imageUrl validator currently fails to correctly extract the file extension when the image URL contains query parameters or fragments (e.g., 'image.qcow2?token=abc'). This change introduces a dedicated function, `getFilenameFromUrl`, which uses the native URL object for robust parsing. This ensures the file suffix validation is always performed on the actual filename, ignoring any trailing parameters. Signed-off-by: devsymo <devsymo@hotmail.com>
b380cae to
7ce9462
Compare
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
The imageUrl validator currently fails to correctly extract the file extension when the image URL contains query parameters or fragments (e.g., 'image.qcow2?token=abc').
This change introduces a dedicated function,
getFilenameFromUrl, which uses the native URL object for robust parsing. This ensures the file suffix validation is always performed on the actual filename, ignoring any trailing parameters.PR Checklist
Related Issue #
5186
Occurred changes and/or fixed issues
Fixes an issue where image validation failed for URLs that contained query parameters (?) or fragments (#). The previous logic incorrectly included these trailing characters when attempting to determine the file extension, resulting in an invalid format error for a valid URL.
Technical notes summary
A new private utility function, getFilenameFromUrl(url), was introduced. This function robustly parses the URL to ensure only the filename part of the path is used for validation.
It attempts to use the native URL object for standard-compliant parsing.
If parsing fails (e.g., if the input is a relative path), it falls back to manual string splitting to remove any query parameters (?) or fragments (#) before extracting the filename.
The main imageUrl validator now uses this new utility function before extracting the file suffix.
Areas or cases that should be tested
Browser Used for Local Testing: [Your Browser, e.g., Chrome/Firefox/Edge]
Image Creation via URL: Test creating a new VM Image using a direct URL.
Case 1 (Success): Use a clean URL (e.g., http://example.com/image.qcow2).
Case 2 (Success - Fixed Case): Use a URL with a query parameter (e.g., http://example.com/image.qcow2?token=abc). This should succeed with no validation error.
Case 3 (Success - Fixed Case): Use a URL with a fragment (e.g., http://example.com/image.raw#latest). This should succeed with no validation error.
Validation Failure: Use a URL with an invalid extension and a query parameter (e.g., http://example.com/image.txt?param=1). This should fail and display the correct format validation error.
Areas which could experience regressions
Any image creation/upload modal that uses the imageUrl validation function.
Other areas of image file validation (though the change is isolated to URL parsing).
Screenshot/Video