Skip to content

Commit 4a2ad4f

Browse files
authored
test(utils): check unrecognized hex string applies standard gray glow… (JhaSourav07#1661)
## Description Adds a new test case to verify that `hexColor()` applies a standard gray fallback when passed unrecognized hex strings (e.g. `ZZZZZZ`, `GGGGGG`, `xyz999`). Fixes JhaSourav07#1555 ## Pillar - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Checklist - [x] I have read the CONTRIBUTING.md file. - [x] I have tested these changes locally. - [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 831d28d + 22bfa19 commit 4a2ad4f

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

lib/svg/sanitizer.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)