feat: sanitize illegal XML characters from outgoing messages (upstream 189050f3)

This commit is contained in:
2026-03-31 19:13:29 +03:00
parent 3fa6542fb8
commit bba6bc5f76
7 changed files with 69 additions and 3 deletions

View File

@@ -846,3 +846,35 @@ prof_whole_occurrences_tests(void** state)
g_slist_free(expected);
expected = NULL;
}
void
str_xml_sanitize__strips_illegal_characters(void** state)
{
// Test NULL input
assert_null(str_xml_sanitize(NULL));
// Test empty string
gchar* res1 = str_xml_sanitize("");
assert_string_equal("", res1);
g_free(res1);
// Test string with no illegal characters
gchar* res2 = str_xml_sanitize("Hello World! \t\n\r");
assert_string_equal("Hello World! \t\n\r", res2);
g_free(res2);
// Test string with illegal characters (0x16 is ^V, 0x01 is ^A)
gchar* res3 = str_xml_sanitize("Hello\x16World\x01!");
assert_string_equal("HelloWorld!", res3);
g_free(res3);
// Test string with mixed legal and illegal control characters
gchar* res4 = str_xml_sanitize("\x09Legal\x0BIllegal\x0ALegal\x1FIllegal\x0DLegal");
assert_string_equal("\tLegalIllegal\nLegalIllegal\rLegal", res4);
g_free(res4);
// Test UTF-8 characters
gchar* res5 = str_xml_sanitize("UTF-8: üñîçøðé \x16 and more");
assert_string_equal("UTF-8: üñîçøðé and more", res5);
g_free(res5);
}

View File

@@ -34,3 +34,4 @@ void prof_whole_occurrences_tests(void** state);
void prof_occurrences_of_large_message_tests(void** state);
void unique_filename_from_url_td(void** state);
void format_call_external_argv_td(void** state);
void str_xml_sanitize__strips_illegal_characters(void** state);

View File

@@ -628,6 +628,7 @@ main(int argc, char* argv[])
cmocka_unit_test(prof_partial_occurrences_tests),
cmocka_unit_test(prof_whole_occurrences_tests),
cmocka_unit_test(prof_occurrences_of_large_message_tests),
cmocka_unit_test(str_xml_sanitize__strips_illegal_characters),
cmocka_unit_test_setup_teardown(returns_no_commands,
load_preferences,