Files
rclone/cmd/serve/dlna/dlna_util_test.go
T
Nick Craig-Wood 8502532c22 serve dlna: fix XML quote escaping for Samsung TV compatibility
Samsung TVs have strict XML parsers that fail to interpret "
(numeric quote entity) correctly within DIDL-Lite metadata, causing
files to appear as empty folders. By replacing " with "
(named quote entity) in all marshaled XML, Samsung TVs can now
properly parse the metadata and display files.

This handles the "Big 5" XML entities that might cause parsing issues:

- " -> " (double quotes)
- ' -> ' (apostrophes)
- & -> &  (ampersands)
- < -> <   (less than)
- > -> >   (greater than)

While Go's xml.Marshal already uses named entities for &, <, >
characters, this ensures complete protection against any edge cases
where numeric entities might be generated. Samsung TVs are known
to have strict XML parsers that can't handle numeric entities.

Fixes #9346
2026-04-24 16:27:09 +01:00

49 lines
1.3 KiB
Go

package dlna
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAdjustXML(t *testing.T) {
tests := []struct {
name string
input []byte
expected string
}{
{
name: "no quotes",
input: []byte(`<title>Simple File</title>`),
expected: `<title>Simple File</title>`,
},
{
name: "numeric quote entities",
input: []byte(`<title>File &#34;with quotes&#34; in name</title>`),
expected: `<title>File &quot;with quotes&quot; in name</title>`,
},
{
name: "mixed entities",
input: []byte(`<title>File &#34;test&#34; &amp; &#34;demo&#34;</title>`),
expected: `<title>File &quot;test&quot; &amp; &quot;demo&quot;</title>`,
},
{
name: "already correct entities",
input: []byte(`<title>File &quot;already correct&quot;</title>`),
expected: `<title>File &quot;already correct&quot;</title>`,
},
{
name: "complex XML structure",
input: []byte(`<item><dc:title>Movie &#34;Title&#34;</dc:title><upnp:artist>Artist &#34;Name&#34;</upnp:artist></item>`),
expected: `<item><dc:title>Movie &quot;Title&quot;</dc:title><upnp:artist>Artist &quot;Name&quot;</upnp:artist></item>`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := adjustXML(tt.input)
assert.Equal(t, tt.expected, result)
})
}
}