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
49 lines
1.3 KiB
Go
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 "with quotes" in name</title>`),
|
|
expected: `<title>File "with quotes" in name</title>`,
|
|
},
|
|
{
|
|
name: "mixed entities",
|
|
input: []byte(`<title>File "test" & "demo"</title>`),
|
|
expected: `<title>File "test" & "demo"</title>`,
|
|
},
|
|
{
|
|
name: "already correct entities",
|
|
input: []byte(`<title>File "already correct"</title>`),
|
|
expected: `<title>File "already correct"</title>`,
|
|
},
|
|
{
|
|
name: "complex XML structure",
|
|
input: []byte(`<item><dc:title>Movie "Title"</dc:title><upnp:artist>Artist "Name"</upnp:artist></item>`),
|
|
expected: `<item><dc:title>Movie "Title"</dc:title><upnp:artist>Artist "Name"</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)
|
|
})
|
|
}
|
|
}
|