diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2011-03-29 14:28:54 +0100 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2011-03-29 14:28:56 +0100 |
commit | c75d42181919d270da1c2ef2b9139781dbed1517 (patch) | |
tree | e23476dee5e9fb44b5173931a1512209dc43cc41 | |
parent | f13a64ac9a75a44b0542df3b8a9ce49a0ebc1f9f (diff) | |
parent | 8e47aa9b34b7fb8957e3b7be74d7c8dc7f49f39e (diff) |
Merge branch 'whitespace-only-bodies'
Reviewed-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Fixes: <https://bugs.freedesktop.org/show_bug.cgi?id=30042>
-rw-r--r-- | tests/wocky-xmpp-reader-test.c | 56 | ||||
-rw-r--r-- | wocky/wocky-xmpp-reader.c | 10 |
2 files changed, 56 insertions, 10 deletions
diff --git a/tests/wocky-xmpp-reader-test.c b/tests/wocky-xmpp-reader-test.c index daab721..8d91e32 100644 --- a/tests/wocky-xmpp-reader-test.c +++ b/tests/wocky-xmpp-reader-test.c @@ -75,6 +75,22 @@ " </branch> " \ "</iq> " +#define WHITESPACE_PADDED_BODY " The Wench is Dead! " + +#define MESSAGE_WITH_WHITESPACE_PADDED_BODY \ +" <message to='morse@thamesvalley.police.uk' " \ +" from='lewis@thamesvalley.police.uk'> " \ +" <body>" WHITESPACE_PADDED_BODY "</body>" \ +" </message>" + + +#define WHITESPACE_ONLY_BODY " " + +#define MESSAGE_WITH_WHITESPACE_ONLY_BODY \ +" <message to='morse@thamesvalley.police.uk' " \ +" from='lewis@thamesvalley.police.uk'> " \ +" <body>" WHITESPACE_ONLY_BODY "</body>" \ +" </message>" static void test_stream_no_stanzas (void) @@ -306,6 +322,44 @@ test_invalid_namespace (void) g_object_unref (reader); } +/* Helper function for the whitespace body tests */ +static void +test_body ( + const gchar *xml, + const gchar *expected_body_text) +{ + WockyXmppReader *reader = wocky_xmpp_reader_new_no_stream (); + WockyStanza *stanza; + WockyNode *body; + + wocky_xmpp_reader_push (reader, (guint8 *) xml, strlen (xml)); + + stanza = wocky_xmpp_reader_pop_stanza (reader); + g_assert (stanza != NULL); + + body = wocky_node_get_child (wocky_stanza_get_top_node (stanza), "body"); + g_assert (body != NULL); + + g_assert_cmpstr (body->content, ==, expected_body_text); + + g_object_unref (stanza); + g_object_unref (reader); +} + +/* Test that whitespace around the text contents of a message isn't ignored */ +static void +test_whitespace_padding (void) +{ + test_body (MESSAGE_WITH_WHITESPACE_PADDED_BODY, WHITESPACE_PADDED_BODY); +} + +/* Test that a message body consisting entirely of whitespace isn't ignored */ +static void +test_whitespace_only (void) +{ + test_body (MESSAGE_WITH_WHITESPACE_ONLY_BODY, WHITESPACE_ONLY_BODY); +} + int main (int argc, char **argv) @@ -323,6 +377,8 @@ main (int argc, g_test_add_func ("/xmpp-reader/no-stream-resetting", test_no_stream_reset); g_test_add_func ("/xmpp-reader/vcard-namespace", test_vcard_namespace); g_test_add_func ("/xmpp-reader/invalid-namespace", test_invalid_namespace); + g_test_add_func ("/xmpp-reader/whitespace-padding", test_whitespace_padding); + g_test_add_func ("/xmpp-reader/whitespace-only", test_whitespace_only); result = g_test_run (); test_deinit (); diff --git a/wocky/wocky-xmpp-reader.c b/wocky/wocky-xmpp-reader.c index efcfeab..17cbbda 100644 --- a/wocky/wocky-xmpp-reader.c +++ b/wocky/wocky-xmpp-reader.c @@ -597,16 +597,6 @@ _end_element_ns (void *user_data, const xmlChar *localname, priv->depth--; - if (priv->node && priv->node->content) - { - /* Remove content if it's purely whitespace */ - const char *c; - for (c = priv->node->content; *c != '\0' && g_ascii_isspace (*c); c++) - ; - if (*c == '\0') - wocky_node_set_content (priv->node, NULL); - } - if (priv->stream_mode && priv->depth == 0) { DEBUG ("Stream ended"); |