Fix XML template xml:space injection for self-closing tags

The injectXmlSpacePreserve function was inserting the attribute AFTER
the self-closing slash in tags like <t t-name="foo"/>, producing
invalid XML: <t t-name="foo"/ xml:space="preserve">

Now correctly inserts before the slash:
<t t-name="foo" xml:space="preserve"/>

This fixes the "attributes construct error at column 33" that appeared
as a red banner in the Odoo webclient list view.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Marc
2026-04-01 00:25:29 +02:00
parent cead612975
commit 8616def7aa
2 changed files with 4 additions and 0 deletions

Binary file not shown.

View File

@@ -317,6 +317,10 @@ func injectXmlSpacePreserve(s string) string {
if idx < 0 {
return s
}
// For self-closing tags like <t t-name="foo"/>, insert before the '/'
if idx > 0 && s[idx-1] == '/' {
return s[:idx-1] + ` xml:space="preserve"` + s[idx-1:]
}
return s[:idx] + ` xml:space="preserve"` + s[idx:]
}