From f31bb88aae60fbd7a7d2e36f6f0bbc0405c9ee42 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Tue, 24 Feb 2026 10:30:18 -0800 Subject: [PATCH] Add missing test cases for processBoxShadow parseLength edge cases (#55715) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55715 Changelog: [Internal] Add tests covering previously untested branches in the parseLength regex and processBoxShadow logic Reviewed By: jorge-cab Differential Revision: D94087958 fbshipit-source-id: b0833200d5e8659d3fd7d39f563dcd950182bf5a --- .../__tests__/processBoxShadow-test.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/react-native/Libraries/StyleSheet/__tests__/processBoxShadow-test.js b/packages/react-native/Libraries/StyleSheet/__tests__/processBoxShadow-test.js index 5ae73928fb0..fb9516041a4 100644 --- a/packages/react-native/Libraries/StyleSheet/__tests__/processBoxShadow-test.js +++ b/packages/react-native/Libraries/StyleSheet/__tests__/processBoxShadow-test.js @@ -213,10 +213,36 @@ describe('processBoxShadow', () => { expect(processBoxShadow('red 10foo 5px 2px 3px,')).toEqual([]); }); + it('should fail to parse decimal number with invalid unit', () => { + expect(processBoxShadow('1.5dog 2px')).toEqual([]); + }); + it('should fail to parse invalid argument', () => { expect(processBoxShadow('red asf 5px 2px 3px')).toEqual([]); }); + it('should parse string with leading dot decimal', () => { + expect(processBoxShadow('.5px 2px')).toEqual([ + { + offsetX: 0.5, + offsetY: 2, + }, + ]); + }); + + it('should parse string with explicit positive sign', () => { + expect(processBoxShadow('+5px 2px')).toEqual([ + { + offsetX: 5, + offsetY: 2, + }, + ]); + }); + + it('should fail to parse trailing dot without fractional digits', () => { + expect(processBoxShadow('10.px 5px')).toEqual([]); + }); + it('should fail to parse negative blur', () => { expect(processBoxShadow('red 5px 2px -3px')).toEqual([]); }); @@ -306,4 +332,15 @@ describe('processBoxShadow', () => { ]), ).toEqual([]); }); + + it('should fail to parse object with unitless non-zero string', () => { + expect( + processBoxShadow([ + { + offsetX: '5', + offsetY: 10, + }, + ]), + ).toEqual([]); + }); });