Skip to content

Commit

Permalink
react-native | Fix a crash on deserilization of props when using 'px'…
Browse files Browse the repository at this point in the history
…/'em' units.

Summary:
A huge set of props use YGValue directly, say something really basic like `margin`/`position`/`padding`/`border`.
All of these according to CSS spec actually support `number | "em" | "px" | %` units, but we are going to throw and hard crash on `em` and `px`, which are unsupported in React Native.

Using `tryTo` instead of `to` (noexcept vs throwing method) for conversion, and treating things like `margin: 50px` same way as we would treat `margin: false` which is not really supported.

Changelog:
    [General][Fixed] - Fixed a crash on deserialization of props when using 'px'/'em' units.

Reviewed By: bvanderhoof

Differential Revision: D37163250

fbshipit-source-id: 59cbe65a821052f6c7e9588b6d4a0ac14e344684
  • Loading branch information
nlutsenko authored and facebook-github-bot committed Jun 15, 2022
1 parent c78baba commit 7078831
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ReactCommon/react/renderer/components/view/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,11 @@ inline void fromRawValue(
YGUnitPercent};
return;
} else {
result = YGValue{folly::to<float>(stringValue), YGUnitPoint};
return;
auto tryValue = folly::tryTo<float>(stringValue);
if (tryValue.hasValue()) {
result = YGValue{tryValue.value(), YGUnitPoint};
return;
}
}
}
}
Expand Down

0 comments on commit 7078831

Please sign in to comment.