@@ -65,34 +65,37 @@ describe('SVG Sanitizer Utilities', () => {
6565 it ( 'returns default fallback for empty string' , ( ) => {
6666 expect ( hexColor ( '' ) ) . toBe ( '000000' ) ;
6767 } ) ;
68+
69+ it ( 'applies standard gray fallback for unrecognized hex strings' , ( ) => {
70+ expect ( hexColor ( 'ZZZZZZ' , '808080' ) ) . toBe ( '808080' ) ;
71+ expect ( hexColor ( 'GGGGGG' , '808080' ) ) . toBe ( '808080' ) ;
72+ expect ( hexColor ( 'xyz999' , '808080' ) ) . toBe ( '808080' ) ;
73+ expect ( hexColor ( '------' , '808080' ) ) . toBe ( '808080' ) ;
74+ } ) ;
6875 } ) ;
6976
7077 describe ( 'sanitizeHexColor' , ( ) => {
7178 it ( 'returns sanitized hex without #' , ( ) => {
7279 expect ( sanitizeHexColor ( '#ff00ff' , '000000' ) ) . toBe ( 'ff00ff' ) ;
7380 expect ( sanitizeHexColor ( 'ff00ff' , '000000' ) ) . toBe ( 'ff00ff' ) ;
74- // Handles multiple leading hashes gracefully
7581 expect ( sanitizeHexColor ( '##ff00ff' , '000000' ) ) . toBe ( 'ff00ff' ) ;
7682 } ) ;
7783
7884 it ( 'returns valid 3-digit hex without #' , ( ) => {
7985 expect ( sanitizeHexColor ( '#f0f' , '000000' ) ) . toBe ( 'f0f' ) ;
8086 expect ( sanitizeHexColor ( 'f0f' , '000000' ) ) . toBe ( 'f0f' ) ;
81- // Handles multiple leading hashes gracefully
8287 expect ( sanitizeHexColor ( '##f0f' , '000000' ) ) . toBe ( 'f0f' ) ;
8388 } ) ;
8489
8590 it ( 'returns valid 8-digit hex without #' , ( ) => {
8691 expect ( sanitizeHexColor ( '#ff00ff00' , '000000' ) ) . toBe ( 'ff00ff00' ) ;
8792 expect ( sanitizeHexColor ( 'ff00ff00' , '000000' ) ) . toBe ( 'ff00ff00' ) ;
88- // Handles multiple leading hashes gracefully
8993 expect ( sanitizeHexColor ( '##ff00ff00' , '000000' ) ) . toBe ( 'ff00ff00' ) ;
9094 } ) ;
9195
9296 it ( 'returns valid 4-digit hex without #' , ( ) => {
9397 expect ( sanitizeHexColor ( '#f0f0' , '000000' ) ) . toBe ( 'f0f0' ) ;
9498 expect ( sanitizeHexColor ( 'f0f0' , '000000' ) ) . toBe ( 'f0f0' ) ;
95- // Handles multiple leading hashes gracefully
9699 expect ( sanitizeHexColor ( '##f0f0' , '000000' ) ) . toBe ( 'f0f0' ) ;
97100 } ) ;
98101
0 commit comments