-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Fix crash by conditional value of aspectRatio style value (#35858) #35859
Conversation
Hi @mym0404! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
I have signed CLA now. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
FYI @gabrieldonadel |
@NickGerleman but do we want this to silently fail without warning the user that they've inputted an invalid |
Co-authored-by: Gabriel Donadel Dall'Agnol <donadeldev@gmail.com>
@gabrieldonadel I handled non-string truthy values like this and add more tests. if (typeof aspectRatio !== 'string') {
if (__DEV__) {
invariant(
!aspectRatio,
'aspectRatio must either be a number, a ratio string or `auto`. You passed: %s',
aspectRatio,
);
}
return;
} |
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.
LGTM
@@ -47,4 +47,18 @@ describe('processAspectRatio', () => { | |||
expect(() => processAspectRatio('1 / 1 1')).toThrowErrorMatchingSnapshot(); | |||
expect(() => processAspectRatio('auto 1/1')).toThrowErrorMatchingSnapshot(); | |||
}); | |||
|
|||
it('should not accept non string falsy types', () => { | |||
const invalidThings = [undefined, null, false]; |
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.
Isn't null
an allowed value for all properties?
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.
It is allowed and ignored silently in this code.
do you mean typing also should be changed to value?: number? | string?
?
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.
Perhaps we could rename this test to it('should ignone non string falsy types', () => {
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.
Done name is changed.
@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Base commit: 8fbcb5c |
@NickGerleman merged this pull request in a8166bd. |
…35859) Summary: fix #35858 ## Changelog 1. Handle not `number` | `string` value passed to `aspectRatio` 2. Add some tests <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [GENERAL] [FIXED] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> Pull Request resolved: #35859 Test Plan: ## Sample [Sample Repository](https://github.com/mym0404/rn-aspect-ratio-crash-sample) Video ![1](https://user-images.githubusercontent.com/33388801/212956921-94b21cda-d841-4588-a05a-d604a82e204c.gif) Reviewed By: necolas Differential Revision: D42575942 Pulled By: NickGerleman fbshipit-source-id: 2f7f46e6e3af85146e4042057477cb6d63b3b279
…5858) (facebook#35859) Summary: fix facebook#35858 ## Changelog 1. Handle not `number` | `string` value passed to `aspectRatio` 2. Add some tests <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [GENERAL] [FIXED] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> Pull Request resolved: facebook#35859 Test Plan: ## Sample [Sample Repository](https://github.com/mym0404/rn-aspect-ratio-crash-sample) Video ![1](https://user-images.githubusercontent.com/33388801/212956921-94b21cda-d841-4588-a05a-d604a82e204c.gif) Reviewed By: necolas Differential Revision: D42575942 Pulled By: NickGerleman fbshipit-source-id: 2f7f46e6e3af85146e4042057477cb6d63b3b279
Summary
fix #35858
Changelog
number
|string
value passed toaspectRatio
Test Plan
Sample
Sample Repository
Video