mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
for #19808 # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] Added/updated tests - [x] Manual QA for all new/changed functionality
36 lines
975 B
Go
36 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)
|
|
})
|
|
}
|
|
}
|