fix(svg): add accessible title and desc tags#116
Conversation
|
@tanu13708-commits is attempting to deploy a commit to the jhasourav07's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Adds semantic accessibility metadata to the generated SVG so screen readers can announce what the badge represents and summarize contribution stats (per Issue #70).
Changes:
- Adds
role="img"to the root<svg>element. - Injects a root-level
<title>containing the username. - Injects a root-level
<desc>summarizingtotalContributionsandlongestStreakfor both static and auto-theme SVG renderers.
Comments suppressed due to low confidence (2)
lib/svg/generator.ts:388
- Same issue in the auto-theme renderer:
<title>/<desc>interpolateparams.userwithout XML escaping, which can produce invalid SVG or allow markup injection. Apply the same XML-escape helper here to keep both render paths consistent and safe.
<title>CommitPulse Stats for ${params.user || 'GitHub User'}</title>
<desc>
${params.user || 'This user'} has ${stats.totalContributions} total contributions and a longest streak of ${stats.longestStreak} days.
</desc>
lib/svg/generator.ts:230
- There are existing Vitest tests for
generateSVG, but none assert the new accessibility output. Please add/adjust tests to verify the root-level<title>and<desc>are present and that usernames are safely escaped (e.g., a username containing&or<). This will prevent regressions across both static and auto-theme code paths.
<title>CommitPulse Stats for ${params.user || 'GitHub User'}</title>
<desc>
${params.user || 'This user'} has ${stats.totalContributions} total contributions and a longest streak of ${stats.longestStreak} days.
</desc>
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <title>CommitPulse Stats for ${params.user || 'GitHub User'}</title> | ||
| <desc> | ||
| ${params.user || 'This user'} has ${stats.totalContributions} total contributions and a longest streak of ${stats.longestStreak} days. | ||
| </desc> |
There was a problem hiding this comment.
yes got it ,let me try to fix
tanu13708-commits
left a comment
There was a problem hiding this comment.
Thanks for the feedback!
I’ve added XML escaping for the username and updated the related title, description, and text fields in both SVG generators.
tanu13708-commits
left a comment
There was a problem hiding this comment.
added the function escapeXML
|
@JhaSourav07 KINDLY check it and please let me know if any errors |
|
can you keep the commit to one? |
This is Mandatory |
|
@JhaSourav07 Ok sir |
Added semantic title and desc tags to improve SVG accessibility for screen readers. Escape XML characters in user title and labels Thanks for pointing this out! I’ve added XML escaping for user-controlled strings using an escapeXML() helper and updated the affected <title>, <desc>, and SVG text usages in both SVG generators to prevent malformed SVG/XML injection issues. Implement escapeXML function for XML escaping Add escapeXML function to sanitize XML strings fix(svg): add accessible title/desc tags and escape XML - Added semantic title and desc tags for accessibility - Implemented escapeXML helper to sanitize user strings - Escaped XML characters in user-controlled labels
b0b5c08 to
bc65568
Compare
|
@JhaSourav07 Hello! I’ve squashed all commits into a single one. |
Fixes #70
Summary
Added semantic
<title>and<desc>tags inside generated SVGs to improve accessibility for screen readers.Changes Made
role="img"to SVG elements<title>tags<desc>tags using contribution statsPillar
Visual Preview
N/A — accessibility-focused update with no visual rendering changes.
Checklist before requesting a review:
CONTRIBUTING.mdfile.localhost:3000/api/streak?user=YOUR_USERNAME).npm run formatandnpm run lintlocally and resolved all errors (CI will fail otherwise).feat(themes): ...,fix(calculate): ...).README.mdif I added a new theme or URL parameter.Result
Screen readers can now interpret contribution statistics without affecting visual rendering.