Skip to content

Commit 74c5188

Browse files
authored
test(sanitizer): add theme color parsing fallback boundary tests (JhaSourav07#1652)
## Description Adds a new `theme color parsing fallbacks` describe block to `lib/svg/sanitizer.test.ts` that verifies the `hexColor` utility correctly falls back to default theme colors when passed invalid hex names. Fixes JhaSourav07#1552 ## Pillar - [x] Other (Bug fix, refactoring, docs) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors. - [x] My commits follow the Conventional Commits format. - [x] I have made sure that i have only one commit to merge in this PR.
2 parents f507787 + 6849aa3 commit 74c5188

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

lib/svg/sanitizer.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,36 @@ describe('SVG Sanitizer Utilities', () => {
236236
expect(sanitizeGoogleFontUrl('https://example.com')).toBe(null);
237237
});
238238
});
239+
240+
describe('theme color parsing fallbacks', () => {
241+
it('resolves invalid hex names to default dark theme background color', () => {
242+
expect(hexColor('not-a-background-color', '0d1117')).toBe('0d1117');
243+
expect(hexColor('background', '0d1117')).toBe('0d1117');
244+
expect(hexColor('', '0d1117')).toBe('0d1117');
245+
});
246+
247+
it('resolves invalid hex names to default dark theme text color', () => {
248+
expect(hexColor('not-a-text-color', 'c9d1d9')).toBe('c9d1d9');
249+
expect(hexColor('text', 'c9d1d9')).toBe('c9d1d9');
250+
expect(hexColor('invalid-text', 'c9d1d9')).toBe('c9d1d9');
251+
});
252+
253+
it('resolves invalid hex names to default dark theme accent color', () => {
254+
expect(hexColor('not-an-accent-color', '58a6ff')).toBe('58a6ff');
255+
expect(hexColor('accent', '58a6ff')).toBe('58a6ff');
256+
expect(hexColor('highlight', '58a6ff')).toBe('58a6ff');
257+
});
258+
259+
it('resolves invalid hex names to light theme colors', () => {
260+
expect(hexColor('not-a-color', 'ffffff')).toBe('ffffff');
261+
expect(hexColor('not-a-color', '24292f')).toBe('24292f');
262+
expect(hexColor('not-a-color', '0969da')).toBe('0969da');
263+
});
264+
265+
it('still resolves valid hex correctly even with theme-like fallbacks', () => {
266+
expect(hexColor('0d1117', '000000')).toBe('0d1117');
267+
expect(hexColor('c9d1d9', '000000')).toBe('c9d1d9');
268+
expect(hexColor('58a6ff', '000000')).toBe('58a6ff');
269+
});
270+
});
239271
});

0 commit comments

Comments
 (0)