The issue involves escaping special characters in sitemap URLs to ensure valid XML output.
The problem is that special characters in sitemap URLs are not escaped, leading to invalid XML. The solution requires proper XML escaping of these characters. A PR is already in progress to address this.
https://github.com/joulev/debug/tree/nextjs-sitemap-escape-ampersand
// app/sitemap.ts
import type { MetadataRoute } from 'next';
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
return [
{
url: 'https://example.com?a=b&c=d',
changeFrequency: 'never',
},
]
}
Current: The & is not escaped, causing the sitemap file to be invalid.
Expected: The URL should be properly escaped. Right now a workaround is required with .replaceAll('&', '&'). But, if this issue is fixed, it will break this workaround, so not even sure if that fix should belong to a new major or not.
Operating System:
Platform: linux
Arch: x64
Version: #25~22.04.1-Ubuntu SMP Thu Jan 16 21:37:09 UTC 2025
Available memory (MB): 7939
Available CPU cores: 2
Binaries:
Node: 18.20.7
npm: 10.8.2
Yarn: 1.22.22
pnpm: 10.6.4
Relevant Packages:
next: 15.3.0-canary.15 // Latest available version is detected (15.3.0-canary.15).
eslint-config-next: N/A
react: 19.0.0
react-dom: 19.0.0
typescript: 5.8.2
Next.js Config:
output: N/A
Metadata
next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)
No response
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!