diff --git a/lib/common/tests/xml/pcmk__xml_escape_test.c b/lib/common/tests/xml/pcmk__xml_escape_test.c index 28b0186a08..d2d5a82d58 100644 --- a/lib/common/tests/xml/pcmk__xml_escape_test.c +++ b/lib/common/tests/xml/pcmk__xml_escape_test.c @@ -1,182 +1,202 @@ /* * Copyright 2024 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU General Public License version 2 * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void assert_escape(const char *str, const char *reference, enum pcmk__xml_escape_type type) { gchar *buf = pcmk__xml_escape(str, type); assert_string_equal(buf, reference); g_free(buf); } static void null_empty(void **state) { assert_null(pcmk__xml_escape(NULL, pcmk__xml_escape_text)); assert_null(pcmk__xml_escape(NULL, pcmk__xml_escape_attr)); + assert_null(pcmk__xml_escape(NULL, pcmk__xml_escape_attr_pretty)); assert_escape("", "", pcmk__xml_escape_text); assert_escape("", "", pcmk__xml_escape_attr); + assert_escape("", "", pcmk__xml_escape_attr_pretty); } static void invalid_type(void **state) { const enum pcmk__xml_escape_type type = (enum pcmk__xml_escape_type) -1; // Easier to ignore invalid type for NULL or empty string assert_null(pcmk__xml_escape(NULL, type)); assert_escape("", "", type); // Otherwise, assert if we somehow passed an invalid type pcmk__assert_asserts(pcmk__xml_escape("he<>llo", type)); } static void escape_unchanged(void **state) { // No escaped characters (note: this string includes single quote at end) const char *unchanged = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "`~!@#$%^*()-_=+/|\\[]{}?.,'"; assert_escape(unchanged, unchanged, pcmk__xml_escape_text); assert_escape(unchanged, unchanged, pcmk__xml_escape_attr); + assert_escape(unchanged, unchanged, pcmk__xml_escape_attr_pretty); } // Ensure special characters get escaped at start, middle, and end static void escape_left_angle(void **state) { const char *l_angle = " #include #include static void null_empty(void **state) { assert_false(pcmk__xml_needs_escape(NULL, pcmk__xml_escape_text)); assert_false(pcmk__xml_needs_escape(NULL, pcmk__xml_escape_attr)); + assert_false(pcmk__xml_needs_escape(NULL, pcmk__xml_escape_attr_pretty)); assert_false(pcmk__xml_needs_escape("", pcmk__xml_escape_text)); assert_false(pcmk__xml_needs_escape("", pcmk__xml_escape_attr)); + assert_false(pcmk__xml_needs_escape("", pcmk__xml_escape_attr_pretty)); } static void invalid_type(void **state) { const enum pcmk__xml_escape_type type = (enum pcmk__xml_escape_type) -1; // Easier to ignore invalid type for NULL or empty string assert_false(pcmk__xml_needs_escape(NULL, type)); assert_false(pcmk__xml_needs_escape("", type)); // Otherwise, assert if we somehow passed an invalid type pcmk__assert_asserts(pcmk__xml_needs_escape("he<>llo", type)); } static void escape_unchanged(void **state) { // No escaped characters (note: this string includes single quote at end) const char *unchanged = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "`~!@#$%^*()-_=+/|\\[]{}?.,'"; assert_false(pcmk__xml_needs_escape(unchanged, pcmk__xml_escape_text)); assert_false(pcmk__xml_needs_escape(unchanged, pcmk__xml_escape_attr)); + assert_false(pcmk__xml_needs_escape(unchanged, + pcmk__xml_escape_attr_pretty)); } // Ensure special characters get escaped at start, middle, and end static void escape_left_angle(void **state) { const char *l_angle_left = "