Problem
When using the -x flag to export a Git repository as XML, the tool fails with the following error:
Error: XML validation error on line 494: invalid character entity & (no semicolon)
Steps to Reproduce
- Clone any repository containing files with special XML characters (like '&')
- Run the following command:
git2gpt -x -s -e -o output.xml /path/to/repository
- Observe the XML validation error
Cause
The issue is in the OutputGitRepoXML function in prompt/prompt.go. The current implementation doesn't properly escape special characters in XML content or handle CDATA sections correctly.
Special XML characters (&, <, >, ", ') need proper escaping when outside CDATA sections, and the CDATA terminator sequence ]]> needs special handling when it appears within file contents.