mirror of
https://github.com/fleetdm/fleet
synced 2026-05-04 22:08:41 +00:00
37 lines
975 B
Go
37 lines
975 B
Go
|
|
package mobileconfig
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/require"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestXMLEscapeString(t *testing.T) {
|
||
|
|
tests := []struct {
|
||
|
|
input string
|
||
|
|
expected string
|
||
|
|
}{
|
||
|
|
// characters that should be escaped
|
||
|
|
{"hello & world", "hello & world"},
|
||
|
|
{"this is a <test>", "this is a <test>"},
|
||
|
|
{"\"quotes\" and 'single quotes'", ""quotes" and 'single quotes'"},
|
||
|
|
{"special chars: \t\n\r", "special chars: 	

"},
|
||
|
|
// no special characters
|
||
|
|
{"plain string", "plain string"},
|
||
|
|
// string that already contains escaped characters
|
||
|
|
{"already <escaped>", "already &lt;escaped&gt;"},
|
||
|
|
// empty string
|
||
|
|
{"", ""},
|
||
|
|
// multiple special characters
|
||
|
|
{"A&B<C>D\"'E\tF\nG\r", "A&B<C>D"'E	F
G
"},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tt := range tests {
|
||
|
|
t.Run(tt.input, func(t *testing.T) {
|
||
|
|
out, err := XMLEscapeString(tt.input)
|
||
|
|
require.NoError(t, err)
|
||
|
|
require.Equal(t, tt.expected, out)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|