From 70788313fedd40fe2e6d1cf15980ce3cca5adaac Mon Sep 17 00:00:00 2001 From: Nikita Lutsenko Date: Wed, 15 Jun 2022 00:12:58 -0700 Subject: [PATCH] react-native | Fix a crash on deserilization of props when using 'px'/'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 --- ReactCommon/react/renderer/components/view/conversions.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ReactCommon/react/renderer/components/view/conversions.h b/ReactCommon/react/renderer/components/view/conversions.h index 2da720e2e59..f70c9f9b9b0 100644 --- a/ReactCommon/react/renderer/components/view/conversions.h +++ b/ReactCommon/react/renderer/components/view/conversions.h @@ -392,8 +392,11 @@ inline void fromRawValue( YGUnitPercent}; return; } else { - result = YGValue{folly::to(stringValue), YGUnitPoint}; - return; + auto tryValue = folly::tryTo(stringValue); + if (tryValue.hasValue()) { + result = YGValue{tryValue.value(), YGUnitPoint}; + return; + } } } }