Skip to content
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

Closed

Conversation

mym0404
Copy link
Contributor

@mym0404 mym0404 commented Jan 17, 2023

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

@mym0404 mym0404 closed this Jan 17, 2023
@mym0404 mym0404 reopened this Jan 17, 2023
@mym0404
Copy link
Contributor Author

mym0404 commented Jan 17, 2023

I have signed CLA now.

@facebook-github-bot
Copy link
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 facebook-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
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
Contributor

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

@NickGerleman
Copy link
Contributor

FYI @gabrieldonadel

@gabrieldonadel
Copy link
Contributor

gabrieldonadel commented Jan 18, 2023

@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

@mym0404
Copy link
Contributor Author

mym0404 commented Jan 18, 2023

@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;
  }

Copy link
Contributor

@gabrieldonadel gabrieldonadel left a 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];
Copy link
Contributor

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?

Copy link
Contributor Author

@mym0404 mym0404 Jan 18, 2023

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
Contributor

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

Copy link
Contributor Author

@mym0404 mym0404 Jan 20, 2023

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
Contributor

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

@facebook-github-bot
Copy link
Contributor

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

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,465,307 +3,438
android hermes armeabi-v7a 7,786,077 +3,615
android hermes x86 8,938,970 +3,851
android hermes x86_64 8,796,812 +3,513
android jsc arm64-v8a 9,650,659 +2,571
android jsc armeabi-v7a 8,385,140 +2,547
android jsc x86 9,712,860 +2,536
android jsc x86_64 10,190,037 +2,591

Base commit: 8fbcb5c
Branch: main

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jan 26, 2023
@facebook-github-bot
Copy link
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
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…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
@cipolleschi cipolleschi mentioned this pull request Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This 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