From 1315d65bf5f1ff355200597708e82120d58a7c4e Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 18 Jul 2024 17:17:16 -0700 Subject: [PATCH] Handle nullish values in `processBoxShadow` and `processFilter` Summary: Viewconfig processors may still get called for nullish values I think. Most other processors explicitly handle these (but some don't??). This returns an empty list, like on parse error, when we have a value, but the value is nullish. Changelog: [Internal] Reviewed By: joevilches Differential Revision: D59933611 fbshipit-source-id: 3f1d89d21977bbe01a05e708aadf1a9451d88083 --- .../react-native/Libraries/StyleSheet/processBoxShadow.js | 5 ++++- packages/react-native/Libraries/StyleSheet/processFilter.js | 6 +++++- .../__tests__/__snapshots__/public-api-test.js.snap | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/react-native/Libraries/StyleSheet/processBoxShadow.js b/packages/react-native/Libraries/StyleSheet/processBoxShadow.js index adba8cd2ce0..dd258f18592 100644 --- a/packages/react-native/Libraries/StyleSheet/processBoxShadow.js +++ b/packages/react-native/Libraries/StyleSheet/processBoxShadow.js @@ -24,9 +24,12 @@ export type ParsedBoxShadow = { }; export default function processBoxShadow( - rawBoxShadows: $ReadOnlyArray | string, + rawBoxShadows: ?($ReadOnlyArray | string), ): Array { const result: Array = []; + if (rawBoxShadows == null) { + return result; + } const boxShadowList = typeof rawBoxShadows === 'string' diff --git a/packages/react-native/Libraries/StyleSheet/processFilter.js b/packages/react-native/Libraries/StyleSheet/processFilter.js index 1c2d3a0ef9c..f865d238d61 100644 --- a/packages/react-native/Libraries/StyleSheet/processFilter.js +++ b/packages/react-native/Libraries/StyleSheet/processFilter.js @@ -36,9 +36,13 @@ type ParsedDropShadow = { }; export default function processFilter( - filter: $ReadOnlyArray | string, + filter: ?($ReadOnlyArray | string), ): $ReadOnlyArray { let result: Array = []; + if (filter == null) { + return result; + } + if (typeof filter === 'string') { // matches on functions with args like "drop-shadow(1.5)" const regex = /([\w-]+)\(([^)]+)\)/g; diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index f968fa563e6..93109e9e4ea 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -8875,7 +8875,7 @@ exports[`public API should not change unintentionally Libraries/StyleSheet/proce inset?: boolean, }; declare export default function processBoxShadow( - rawBoxShadows: $ReadOnlyArray | string + rawBoxShadows: ?($ReadOnlyArray | string) ): Array; " `; @@ -8916,7 +8916,7 @@ type ParsedDropShadow = { color?: ColorValue, }; declare export default function processFilter( - filter: $ReadOnlyArray | string + filter: ?($ReadOnlyArray | string) ): $ReadOnlyArray; " `;