mirror of
https://github.com/alexandrev/xslt-lab.git
synced 2026-09-13 08:43:16 +00:00
Fix: html.UnescapeString corrupts XML params with & entities
When an XML parameter value starts with '<', html.UnescapeString was incorrectly called, converting & → & and breaking well-formed XML that contained entity references. Only apply HTML decoding when the value starts with '<' (HTML-encoded XML sent from a form field). Fixes: 'The entity name must immediately follow the & in entity reference' error reported when XML input contains & characters escaped as &. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+6
-1
@@ -199,8 +199,13 @@ func main() {
|
||||
continue
|
||||
}
|
||||
trimmed := strings.TrimSpace(v)
|
||||
if strings.HasPrefix(trimmed, "<") || strings.HasPrefix(trimmed, "<") {
|
||||
if strings.HasPrefix(trimmed, "<") {
|
||||
// HTML-encoded XML (e.g. sent from a form field): decode first
|
||||
fileParams[k] = html.UnescapeString(trimmed)
|
||||
} else if strings.HasPrefix(trimmed, "<") {
|
||||
// Already valid XML — do NOT call html.UnescapeString or it will
|
||||
// convert & → & and break well-formed entity references
|
||||
fileParams[k] = trimmed
|
||||
} else {
|
||||
stringParams[k] = v
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user