Skip to content

Commit c2b038f

Browse files
authored
style(test): format sanitizeFont tests (JhaSourav07#609)
## Description Fixes JhaSourav07#343 Expanded test coverage for `sanitizeFont` in `lib/svg/sanitizer.test.ts`. ### Added edge case tests * null input returns null * whitespace-only input returns null * valid font names with spaces are preserved * numeric font names are allowed * script injection attempts are sanitized * invalid characters that sanitize to empty return null ## Pillar * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (test-only changes) ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] I have tested these changes locally. * [x] I have run `npm run format` and `npm run lint` locally and resolved all errors. * [x] My commits follow the Conventional Commits format. * [ ] I have updated `README.md` if needed. * [x] I have started the repo. * [x] I have made sure that i have only one commit to merge in this PR. * [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard (not applicable). * [ ] (Recommended) I joined the CommitPulse Discord community. Close JhaSourav07#343
2 parents cccf6c7 + 7aa3749 commit c2b038f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

lib/svg/sanitizer.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,30 @@ describe('SVG Sanitizer Utilities', () => {
9797
it('returns null for completely invalid font', () => {
9898
expect(sanitizeFont('!!!')).toBe(null);
9999
});
100+
101+
it('returns null for null input', () => {
102+
expect(sanitizeFont(null)).toBe(null);
103+
});
104+
105+
it('returns null for whitespace-only input', () => {
106+
expect(sanitizeFont(' ')).toBe(null);
107+
});
108+
109+
it('preserves valid font names with spaces', () => {
110+
expect(sanitizeFont('Fira Code')).toBe('Fira Code');
111+
});
112+
113+
it('allows numeric font names', () => {
114+
expect(sanitizeFont('123')).toBe('123');
115+
});
116+
117+
it('sanitizes script injection attempts', () => {
118+
expect(sanitizeFont('<script>alert(1)</script>')).toBe('scriptalert1script');
119+
});
120+
121+
it('returns null when sanitization removes all characters', () => {
122+
expect(sanitizeFont('@@@')).toBe(null);
123+
});
100124
});
101125

102126
describe('sanitizeGoogleFontUrl', () => {

0 commit comments

Comments
 (0)