Mercurial > pidgin
diff libpurple/tests/test_xmlnode.c @ 32038:8d3b5853b017
xmlnode: Add xmlnode_strip_prefixes
This is largely based on a patch from Thijs (sphynx/xnyhps) Alkemade, with
some modifications by me to try to maintain namespaces of elements
as best as we can.
I also rewrote xmlnode_get_default_namespace not to use recursion.
References #14529
| author | Paul Aurich <paul@darkrain42.org> |
|---|---|
| date | Sun, 04 Sep 2011 21:06:26 +0000 |
| parents | 114a98da1a5f |
| children |
line wrap: on
line diff
--- a/libpurple/tests/test_xmlnode.c Sun Sep 04 18:52:18 2011 +0000 +++ b/libpurple/tests/test_xmlnode.c Sun Sep 04 21:06:26 2011 +0000 @@ -81,6 +81,41 @@ } END_TEST + +START_TEST(test_strip_prefixes) +{ + const char *xml_doc = "<message xmlns='jabber:client' from='user@gmail.com/resource' to='another_user@darkrain42.org' type='chat' id='purple'>" + "<cha:active xmlns:cha='http://jabber.org/protocol/chatstates'/>" + "<body>xvlc xvlc</body>" + "<im:html xmlns:im='http://jabber.org/protocol/xhtml-im'>" + "<xht:body xmlns:xht='http://www.w3.org/1999/xhtml'>" + "<xht:p>xvlc <xht:span style='font-weight: bold;'>xvlc</xht:span></xht:p>" + "</xht:body>" + "</im:html>" + "</message>"; + const char *out = "<message xmlns='jabber:client' from='user@gmail.com/resource' to='another_user@darkrain42.org' type='chat' id='purple'>" + "<active xmlns:cha='http://jabber.org/protocol/chatstates' xmlns='http://jabber.org/protocol/chatstates'/>" + "<body>xvlc xvlc</body>" + "<html xmlns:im='http://jabber.org/protocol/xhtml-im' xmlns='http://jabber.org/protocol/xhtml-im'>" + "<body xmlns:xht='http://www.w3.org/1999/xhtml' xmlns='http://www.w3.org/1999/xhtml'>" + "<p>xvlc <span style='font-weight: bold;'>xvlc</span></p>" + "</body>" + "</html>" + "</message>"; + char *str; + xmlnode *xml; + + xml = xmlnode_from_str(xml_doc, -1); + fail_if(xml == NULL, "Failed to parse XML"); + + xmlnode_strip_prefixes(xml); + str = xmlnode_to_str(xml, NULL); + assert_string_equal_free(out, str); + + xmlnode_free(xml); +} +END_TEST + Suite * xmlnode_suite(void) { @@ -89,6 +124,7 @@ TCase *tc = tcase_create("xmlnode"); tcase_add_test(tc, test_xmlnode_billion_laughs_attack); tcase_add_test(tc, test_xmlnode_prefixes); + tcase_add_test(tc, test_strip_prefixes); suite_add_tcase(s, tc);
