mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 00:09:23 +02:00
[PR #505] [MERGED] fix: escape XML special characters in sitemap generation #627
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#627
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/505
Author: @NathanDrake2406
Created: 3/12/2026
Status: ✅ Merged
Merged: 3/12/2026
Merged by: @james-elicx
Base:
main← Head:fix/sitemap-xml-escaping📝 Commits (1)
15a6d5dfix: escape XML special characters in sitemap generation📊 Changes
2 files changed (+78 additions, -20 deletions)
View changed files
📝
packages/vinext/src/server/metadata-routes.ts(+24 -12)📝
tests/metadata-routes.test.ts(+54 -8)📄 Description
Summary
sitemapToXml()interpolated user-supplied values directly into XML without escaping&(extremely common with query params like?q=a&b=2) produced invalid XML<,>,", or&also broke the XML structureFix
Add
escapeXml()helper that handles all five XML special characters (&<>"') and apply it to every user-supplied string value in the sitemap serializer: URLs, alternate hrefs, hreflang values, image locs, video titles/descriptions/tags/URLs, uploader names/info, restriction/platform attributes.Numeric fields (duration, view_count, rating) and controlled enums (family_friendly, live) are left unescaped since they can't contain XML-special characters.
This intentionally diverges from Next.js's
resolveSitemap()which also raw-interpolates. The existing parity test "matches Next's raw interpolation for XML-sensitive values" has been updated to assert correct XML escaping instead.Test plan
&produce&in<loc>,<image:loc>, andhrefattributes&,<,>,"are properly escaped🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.