Skip to content

Commit c4301ba

Browse files
Test/escape xml variation (JhaSourav07#1651)
## Description test(utils): check boundary robustness of escapeXML helper (Variation 3) Fixes JhaSourav07#1568 ## Pillar - [ ] 🎨 Pillar 1 β€” New Theme Design - [ ] πŸ“ Pillar 2 β€” Geometric SVG Improvement - [ ] πŸ• Pillar 3 β€” Timezone Logic Optimization - [x] πŸ› οΈ Other (Bug fix, refactoring, docs) ## Visual Preview ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [ ] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
1 parent ad6ba28 commit c4301ba

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

β€Žapp/api/wrapped/route.tsβ€Ž

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ import { themes } from '@/lib/svg/themes';
1010
const SVG_CSP_HEADER =
1111
"default-src 'none'; style-src 'unsafe-inline' https://fonts.googleapis.com; font-src https://fonts.gstatic.com; connect-src https://fonts.gstatic.com;";
1212

13-
class ValidationError extends Error {
14-
constructor(message: string) {
15-
super(message);
16-
this.name = 'ValidationError';
17-
}
18-
}
19-
2013
function escapeSVGText(value: string): string {
2114
return value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
2215
}

β€Žapp/customize/components/ThemeQuickPresets.test.tsxβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
22
import { fireEvent, render, screen } from '@testing-library/react';
33
import { ThemeQuickPresets } from './ThemeQuickPresets';
44
import { THEME_KEYS } from '../types';
5-
import { themes } from '../../../lib/svg/themes';
65

76
const validKeys = THEME_KEYS.filter((k) => k !== 'auto' && k !== 'random');
87

β€Žlib/svg/generator.test.tsβ€Ž

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,38 @@ describe('Radar Scan Line Animation Alignment', () => {
13041304
expect(result).not.toEqual(longUsername);
13051305
});
13061306

1307+
it('should cleanly convert exact boundary characters (<script>&") to safe XML entities', () => {
1308+
// Arrange: The specific boundary string requested in Issue #1568
1309+
const boundaryInput = '<script>&"';
1310+
1311+
// Act
1312+
const result = escapeXML(boundaryInput);
1313+
1314+
// Assert:
1315+
// < becomes &lt;
1316+
// > becomes &gt;
1317+
// & becomes &amp;
1318+
// " becomes &quot;
1319+
expect(result).toBe('&lt;script&gt;&amp;&quot;');
1320+
});
1321+
1322+
it('should handle mixed real-world inputs correctly without double-escaping', () => {
1323+
// Arrange: A realistic edge case for a GitHub user profile
1324+
const mixedInput = 'R&D <"Team">';
1325+
1326+
// Act
1327+
const result = escapeXML(mixedInput);
1328+
1329+
// Assert
1330+
expect(result).toBe('R&amp;D &lt;&quot;Team&quot;&gt;');
1331+
});
1332+
1333+
it('should handle empty and safe inputs gracefully', () => {
1334+
// Assert: Empty inputs and regular strings remain untouched
1335+
expect(escapeXML('')).toBe('');
1336+
expect(escapeXML('CommitPulse')).toBe('CommitPulse');
1337+
});
1338+
13071339
it('renders long usernames as truncated SVG labels without breaking geometry', () => {
13081340
const longUsername = 'ThisIsAVeryLongUsernameThatExceedsThirtyCharacters';
13091341
const svg = generateSVG(

0 commit comments

Comments
Β (0)