-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Validate SVG ratio in Image validator #59265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
5f2304e
to
9e7ecc1
Compare
stof
requested changes
Dec 19, 2024
9e7ecc1
to
cef5a7b
Compare
Thanks @stof, I fixed the code according to your comments. |
stof
reviewed
Dec 19, 2024
9281d5c
to
4b270ff
Compare
stof
approved these changes
Dec 22, 2024
OskarStark
reviewed
Dec 22, 2024
OskarStark
reviewed
Dec 22, 2024
src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php
Outdated
Show resolved
Hide resolved
8726444
to
1c16abf
Compare
Thanks @OskarStark, I applied your suggestions. |
xabbuh
reviewed
Dec 28, 2024
7.3 | ||
--- | ||
|
||
* Allow `Image` constraint to check SVG ratio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
* Allow `Image` constraint to check SVG ratio | |
* Add support for ratio checks for SVG files to the `Image` |
fabpot
approved these changes
Dec 29, 2024
1c16abf
to
c4ad092
Compare
Thank you @maximecolin. |
javiereguiluz
added a commit
to symfony/symfony-docs
that referenced
this pull request
Jan 2, 2025
This PR was merged into the 6.4 branch. Discussion ---------- [Validator] Cannot validate svg image size As an addition of #20496 and considering what is described in related [code PR](symfony/symfony#59265) I think it can be helpful to explicit mention this restriction for SVG images Commits ------- 248d4ff cannot validate svg image size
Merged
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.
Implement ratio check for SVG images. Checking SGV size is not relevant as a SVG image can be enlarged without loss, but ratio can be important to check.
Currently, the validator add a violation with
SIZE_NOT_DETECTED_ERROR
in case of SVG image.SVG size is guessed from viewbox, width and height attributes. Viewbox will provides default size, width and height can override viewbox size if they are number. Width and height as percentage are ignored as the final size will depend on the container.
I use
preg_match
instead of\DomDocument
orsimplexml
functions to extract viewBox, width and height in order to avoid new dependencies onext-dom
orext-simplexml
.In case of SVG,
minWidth
,maxWidth
,minHeight
,maxHeight
,minPixels
andmaxPixels
are ignored because not relevant. OnlymaxRatio
,minRatio
,allowSquare
,allowLandscape
andallowPortrait
can generate violations, like suggested in the comments of the abandoned #45486.