Skip to content

Fix crash by conditional value of aspectRatio style value (#35858) - #35859

Closed
mym0404 wants to merge 6 commits into
react:mainfrom
mym0404:fix-aspect-ratio-conditional-value
Closed

Fix crash by conditional value of aspectRatio style value (#35858)#35859
mym0404 wants to merge 6 commits into
react:mainfrom
mym0404:fix-aspect-ratio-conditional-value

Conversation

@mym0404

@mym0404mym0404 commented Jan 17, 2023

Copy link
Copy Markdown
Contributor

Summary

fix#35858

Changelog

  1. Handle not number | string value passed to aspectRatio
  2. Add some tests

Test Plan

Sample

Sample Repository

Video

1

@facebook-github-bot

Copy link
Copy Markdown
Contributor

Hi @mym0404!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@mym0404mym0404 closed this Jan 17, 2023
@mym0404mym0404 reopened this Jan 17, 2023
@mym0404

mym0404 commented Jan 17, 2023

Copy link
Copy Markdown
ContributorAuthor

I have signed CLA now.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-botfacebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 17, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@NickGerleman

Copy link
Copy Markdown
Contributor

FYI @gabrieldonadel

@gabrieldonadel

gabrieldonadel commented Jan 18, 2023

Copy link
Copy Markdown
Collaborator

@NickGerleman but do we want this to silently fail without warning the user that they've inputted an invalid aspectRatio? I remember discussing this with @necolas a while ago

Comment threadLibraries/StyleSheet/processAspectRatio.js
Comment threadLibraries/StyleSheet/processAspectRatio.js
@mym0404

Copy link
Copy Markdown
ContributorAuthor

@gabrieldonadel I handled non-string truthy values like this and add more tests.

if(typeofaspectRatio!=='string'){if(__DEV__){invariant(!aspectRatio,'aspectRatio must either be a number, a ratio string or `auto`. You passed: %s',aspectRatio,);}return;}

@gabrieldonadelgabrieldonadel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

});

it('should not accept non string falsy types', () => {
const invalidThings = [undefined, null, false];

Copy link
Copy Markdown

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?

@mym0404mym0404Jan 18, 2023

Copy link
Copy Markdown
ContributorAuthor

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??

Copy link
Copy Markdown
Collaborator

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', () => {

@mym0404mym0404Jan 20, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done name is changed.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Comment threadLibraries/StyleSheet/__tests__/processAspectRatio-test.js Outdated
Comment threadLibraries/StyleSheet/__tests__/processAspectRatio-test.js Outdated
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@analysis-bot

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a8,465,307+3,438
androidhermesarmeabi-v7a7,786,077+3,615
androidhermesx868,938,970+3,851
androidhermesx86_648,796,812+3,513
androidjscarm64-v8a9,650,659+2,571
androidjscarmeabi-v7a8,385,140+2,547
androidjscx869,712,860+2,536
androidjscx86_6410,190,037+2,591

Base commit: 8fbcb5c
Branch: main

@facebook-github-botfacebook-github-bot added the Merged This PR has been merged. label Jan 26, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@NickGerleman merged this pull request in a8166bd.

kelset pushed a commit that referenced this pull request Jan 30, 2023
…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
@cipolleschicipolleschi mentioned this pull request Oct 11, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.MergedThis PR has been merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[0.71.0] Provides aspectRatio conditionally cause js crash

6 participants

@mym0404@facebook-github-bot@NickGerleman@gabrieldonadel@analysis-bot@necolas