axis-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billblo...@apache.org
Subject svn commit: r1830721 - in /axis/axis2/c/core/trunk/guththila: include/guththila_xml_writer.h src/guththila_xml_writer.c tests/Makefile.am tests/test_attribute.cc
Date Wed, 02 May 2018 03:39:15 GMT
Author: billblough
Date: Wed May  2 03:39:14 2018
New Revision: 1830721

URL: http://svn.apache.org/viewvc?rev=1830721&view=rev
Log:
Fix guththila serialization of special chars in attr

JIRA: AXIS2C-1627

Modified:
    axis/axis2/c/core/trunk/guththila/include/guththila_xml_writer.h
    axis/axis2/c/core/trunk/guththila/src/guththila_xml_writer.c
    axis/axis2/c/core/trunk/guththila/tests/Makefile.am
    axis/axis2/c/core/trunk/guththila/tests/test_attribute.cc

Modified: axis/axis2/c/core/trunk/guththila/include/guththila_xml_writer.h
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/guththila/include/guththila_xml_writer.h?rev=1830721&r1=1830720&r2=1830721&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/guththila/include/guththila_xml_writer.h (original)
+++ axis/axis2/c/core/trunk/guththila/include/guththila_xml_writer.h Wed May  2 03:39:14 2018
@@ -260,6 +260,19 @@ GUTHTHILA_EXPORT int GUTHTHILA_CALL guth
     const axutil_env_t * env);
 
 /*
+ * Write a buffer with special chars on it
+ * The special chars will be escaped
+ * @param wr pointer to the writer
+ * @param buff character string
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_escaped_buffer(
+    guththila_xml_writer_t * wr,
+    char *buff,
+    const axutil_env_t * env);
+
+
+/*
  * Start to write an empty element with the given name. 
  * @param wr pointer to the writer
  * @param name name of the element

Modified: axis/axis2/c/core/trunk/guththila/src/guththila_xml_writer.c
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/guththila/src/guththila_xml_writer.c?rev=1830721&r1=1830720&r2=1830721&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/guththila/src/guththila_xml_writer.c (original)
+++ axis/axis2/c/core/trunk/guththila/src/guththila_xml_writer.c Wed May  2 03:39:14 2018
@@ -725,7 +725,7 @@ guththila_write_characters(
     guththila_char_t *buff,
     const axutil_env_t * env)
 {
-    size_t len = strlen(buff);
+
     if(wr->status == START)
     {
         wr->status = BEGINING;
@@ -741,39 +741,7 @@ guththila_write_characters(
     {
         return GUTHTHILA_FAILURE;
     }
-    while(len > 0)
-    {
-        size_t i = 0;
-        /* scan buffer until the next special character (&, <, >, ', ") these need
to be escaped,
-         * otherwise XML will not be valid*/
-        guththila_char_t *pos = (guththila_char_t*)strpbrk(buff, "&<>'\"");
-        if(pos)
-        {
-            i = pos - buff;
-        }
-        else
-        {
-            i = len;
-        }
-
-        /* write everything until the special character */
-        if(i > 0)
-        {
-            guththila_write(wr, buff, i, env);
-            buff += i;
-            len -= i;
-        }
-        /* replace the character with the appropriate sequence */
-        if(len > 0)
-        {
-            if(AXIS2_SUCCESS != guththila_write_escape_character(wr, buff, env))
-                return GUTHTHILA_FAILURE;
-            /* skip the character */
-            buff++;
-            len--;
-        }
-    }
-    return GUTHTHILA_SUCCESS;
+    return guththila_write_escaped_buffer(wr,buff,env);
 }
 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
@@ -842,6 +810,50 @@ guththila_write_escape_character(
 }
 
 GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_write_escaped_buffer(
+    guththila_xml_writer_t * wr,
+    char *buff,
+    const axutil_env_t * env)
+{
+    size_t len = strlen(buff);
+
+    while(len > 0)
+    {
+        size_t i = 0;
+        /* scan buffer until the next special character (&, <, >, ', ") these need
to be escaped,
+         * otherwise XML will not be valid*/
+        guththila_char_t *pos = (guththila_char_t*)strpbrk(buff, "&<>'\"");
+        if(pos)
+        {
+            i = pos - buff;
+        }
+        else
+        {
+            i = len;
+        }
+
+        /* write everything until the special character */
+        if(i > 0)
+        {
+            guththila_write(wr, buff, i, env);
+            buff += i;
+            len -= i;
+        }
+        /* replace the character with the appropriate sequence */
+        if(len > 0)
+        {
+            if(AXIS2_SUCCESS != guththila_write_escape_character(wr, buff, env))
+                return GUTHTHILA_FAILURE;
+            /* skip the character */
+            buff++;
+            len--;
+        }
+    }
+    return GUTHTHILA_SUCCESS;
+
+}
+
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
 guththila_write_empty_element(
     guththila_xml_writer_t * wr,
     guththila_char_t *start_element,
@@ -1087,7 +1099,8 @@ guththila_write_attribute(
         guththila_write(wr, " ", 1u, env);
         guththila_write(wr, localname, strlen(localname), env);
         guththila_write(wr, "=\"", 2u, env);
-        guththila_write(wr, value, strlen(value), env);
+        if(guththila_write_escaped_buffer(wr, value, env)!=GUTHTHILA_SUCCESS)
+        	return GUTHTHILA_FAILURE;
         guththila_write(wr, "\"", 1u, env);
         return GUTHTHILA_SUCCESS;
     }
@@ -1147,7 +1160,8 @@ guththila_write_attribute_with_prefix(
                     guththila_write(wr, ":", 1u, env);
                     guththila_write(wr, localname, strlen(localname), env);
                     guththila_write(wr, "=\"", 2u, env);
-                    guththila_write(wr, value, strlen(value), env);
+                    if(guththila_write_escaped_buffer(wr, value, env)!=GUTHTHILA_SUCCESS)
+                    	return GUTHTHILA_FAILURE;
                     guththila_write(wr, "\"", 1u, env);
                     return GUTHTHILA_SUCCESS;
                 }
@@ -1194,7 +1208,8 @@ guththila_write_attribute_with_namespace
                     guththila_write(wr, ":", 1u, env);
                     guththila_write(wr, loc_name, strlen(loc_name), env);
                     guththila_write(wr, "=\"", 2u, env);
-                    guththila_write(wr, value, strlen(value), env);
+                    if(guththila_write_escaped_buffer(wr, value, env)!=GUTHTHILA_SUCCESS)
+                    	return GUTHTHILA_FAILURE;
                     guththila_write(wr, "\"", 1u, env);
                     return GUTHTHILA_SUCCESS;
                 }

Modified: axis/axis2/c/core/trunk/guththila/tests/Makefile.am
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/guththila/tests/Makefile.am?rev=1830721&r1=1830720&r2=1830721&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/guththila/tests/Makefile.am (original)
+++ axis/axis2/c/core/trunk/guththila/tests/Makefile.am Wed May  2 03:39:14 2018
@@ -20,7 +20,8 @@ SUBDIRS =
 test_guththila_SOURCES = test_guththila.cc
 
 AM_CPPFLAGS = -I$(top_builddir)/include \
-				-I ../../util/include
+				-I ../../util/include \
+				-I ../../axiom/include
 
 test_guththila_LDADD = \
 				 $(top_builddir)/src/libguththila.la \
@@ -33,5 +34,6 @@ test_attribute_SOURCES = test_attribute.
 test_attribute_LDADD = \
 				 $(top_builddir)/src/libguththila.la \
 				 ../../util/src/libaxutil.la \
+				 ../../axiom/src/om/libaxis2_axiom.la \
 				 $(top_builddir)/$(GTEST)/libgtest.a \
 				 $(top_builddir)/$(GTEST)/libgtest_main.a

Modified: axis/axis2/c/core/trunk/guththila/tests/test_attribute.cc
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/guththila/tests/test_attribute.cc?rev=1830721&r1=1830720&r2=1830721&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/guththila/tests/test_attribute.cc (original)
+++ axis/axis2/c/core/trunk/guththila/tests/test_attribute.cc Wed May  2 03:39:14 2018
@@ -18,6 +18,7 @@
 #include <gtest/gtest.h>
 
 #include <guththila.h>
+#include <axiom.h>
 
 
 #define BUF_SIZE 256
@@ -43,15 +44,11 @@ class TestAttribute: public ::testing::T
         void TearDown()
         {
 
-            guththila_reader_free(m_reader, m_env);
-            m_reader = nullptr;
-            guththila_un_init(m_parser, m_env);
-            m_parser = nullptr;
             axutil_env_free(m_env);
 
         }
 
-        guththila_reader_t *m_reader;
+        guththila_reader_t *m_reader = nullptr;
         axutil_allocator_t *m_allocator;
         axutil_env_t *m_env;
         guththila_t *m_parser;
@@ -85,6 +82,11 @@ TEST_F(TestAttribute, test_attribute) {
     ASSERT_STREQ(guththila_get_attribute_name(m_parser, att, m_env), "color");
     ASSERT_STREQ(guththila_get_attribute_value(m_parser, att, m_env), "brown");
 
+    guththila_reader_free(m_reader, m_env);
+    m_reader = nullptr;
+    guththila_un_init(m_parser, m_env);
+    m_parser = nullptr;
+
 }
 
 
@@ -129,4 +131,26 @@ TEST_F(TestAttribute, test_attribute_pre
     ASSERT_STREQ(guththila_get_attribute_name(m_parser, att, m_env), "mustUnderstand");
     ASSERT_STREQ(guththila_get_attribute_value(m_parser, att, m_env), "0");
 
+    guththila_reader_free(m_reader, m_env);
+    m_reader = nullptr;
+    guththila_un_init(m_parser, m_env);
+    m_parser = nullptr;
+
+}
+
+/* AXIS2C-1627 */
+TEST_F(TestAttribute, test_special_char_serialization)
+{
+     axiom_namespace_t * ns = axiom_namespace_create(m_env, "namespace", "ns");
+
+     axiom_node_t * node;
+     axiom_element_t * element = axiom_element_create(m_env, NULL, "el", ns, &node);
+
+     axiom_element_set_text(element, m_env, "T1 & T2", node);
+     axiom_element_add_attribute(element, m_env, axiom_attribute_create(m_env, "name", "A1
& A2", NULL), node);
+
+     axis2_char_t * xml = axiom_node_to_string(node, m_env);
+
+     ASSERT_STREQ(xml, "<ns:el xmlns:ns=\"namespace\" name=\"A1 &amp; A2\">T1 &amp;
T2</ns:el>");
+
 }



Mime
View raw message