@@ -233,4 +233,36 @@ describe('SVG Sanitizer Utilities', () => {
233233 expect ( sanitizeGoogleFontUrl ( 'https://example.com' ) ) . toBe ( null ) ;
234234 } ) ;
235235 } ) ;
236+
237+ describe ( 'theme color parsing fallbacks' , ( ) => {
238+ it ( 'resolves invalid hex names to default dark theme background color' , ( ) => {
239+ expect ( hexColor ( 'not-a-background-color' , '0d1117' ) ) . toBe ( '0d1117' ) ;
240+ expect ( hexColor ( 'background' , '0d1117' ) ) . toBe ( '0d1117' ) ;
241+ expect ( hexColor ( '' , '0d1117' ) ) . toBe ( '0d1117' ) ;
242+ } ) ;
243+
244+ it ( 'resolves invalid hex names to default dark theme text color' , ( ) => {
245+ expect ( hexColor ( 'not-a-text-color' , 'c9d1d9' ) ) . toBe ( 'c9d1d9' ) ;
246+ expect ( hexColor ( 'text' , 'c9d1d9' ) ) . toBe ( 'c9d1d9' ) ;
247+ expect ( hexColor ( 'invalid-text' , 'c9d1d9' ) ) . toBe ( 'c9d1d9' ) ;
248+ } ) ;
249+
250+ it ( 'resolves invalid hex names to default dark theme accent color' , ( ) => {
251+ expect ( hexColor ( 'not-an-accent-color' , '58a6ff' ) ) . toBe ( '58a6ff' ) ;
252+ expect ( hexColor ( 'accent' , '58a6ff' ) ) . toBe ( '58a6ff' ) ;
253+ expect ( hexColor ( 'highlight' , '58a6ff' ) ) . toBe ( '58a6ff' ) ;
254+ } ) ;
255+
256+ it ( 'resolves invalid hex names to light theme colors' , ( ) => {
257+ expect ( hexColor ( 'not-a-color' , 'ffffff' ) ) . toBe ( 'ffffff' ) ;
258+ expect ( hexColor ( 'not-a-color' , '24292f' ) ) . toBe ( '24292f' ) ;
259+ expect ( hexColor ( 'not-a-color' , '0969da' ) ) . toBe ( '0969da' ) ;
260+ } ) ;
261+
262+ it ( 'still resolves valid hex correctly even with theme-like fallbacks' , ( ) => {
263+ expect ( hexColor ( '0d1117' , '000000' ) ) . toBe ( '0d1117' ) ;
264+ expect ( hexColor ( 'c9d1d9' , '000000' ) ) . toBe ( 'c9d1d9' ) ;
265+ expect ( hexColor ( '58a6ff' , '000000' ) ) . toBe ( '58a6ff' ) ;
266+ } ) ;
267+ } ) ;
236268} ) ;
0 commit comments