Fix parsing of CDATA sections

JIRA: AXIS2C-1453
diff --git a/axiom/configure.ac b/axiom/configure.ac
index f55ba91..a952199 100644
--- a/axiom/configure.ac
+++ b/axiom/configure.ac
@@ -266,6 +266,7 @@
     gtest/Makefile \
     test/Makefile \
     test/om/Makefile \
+    test/parser/Makefile \
     test/soap/Makefile \
     test/util/Makefile \
     test/xpath/Makefile \
diff --git a/axiom/test/Makefile.am b/axiom/test/Makefile.am
index e05ad29..b6fe541 100644
--- a/axiom/test/Makefile.am
+++ b/axiom/test/Makefile.am
@@ -13,5 +13,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 TESTS =
-SUBDIRS = om soap util xpath
+SUBDIRS = om soap util xpath parser
 EXTRA_DIST = resources
diff --git a/axiom/test/parser/Makefile.am b/axiom/test/parser/Makefile.am
new file mode 100644
index 0000000..9824a85
--- /dev/null
+++ b/axiom/test/parser/Makefile.am
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+TESTS = test_parser
+noinst_PROGRAMS = test_parser
+check_PROGRAMS = test_parser
+SUBDIRS =
+
+test_parser_SOURCES = test_parser.cc
+
+test_parser_LDADD = $(top_builddir)/../util/src/libaxutil.la \
+				 $(top_builddir)/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
+				 $(top_builddir)/src/om/libaxis2_axiom.la \
+				 $(top_builddir)/$(GTEST)/libgtest.a \
+				 $(top_builddir)/$(GTEST)/libgtest_main.a
+
+AM_CPPFLAGS = -I$(top_srcdir)/include \
+            -I$(top_srcdir)/src/parser \
+			-I $(top_srcdir)/../util/include \
+			-I $(GTEST_DIR)/include
diff --git a/axiom/test/parser/test_parser.cc b/axiom/test/parser/test_parser.cc
new file mode 100644
index 0000000..9a3c918
--- /dev/null
+++ b/axiom/test/parser/test_parser.cc
@@ -0,0 +1,76 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <gtest/gtest.h>
+
+#include <axiom.h>
+
+
+class TestParser: public ::testing::Test
+{
+
+    protected:
+        void SetUp()
+        {
+            m_allocator = axutil_allocator_init(NULL);
+            ASSERT_NE(m_allocator, nullptr);
+            m_env = axutil_env_create(m_allocator);
+            ASSERT_NE(m_env, nullptr);
+        }
+
+        void TearDown()
+        {
+            axutil_env_free(m_env);
+        }
+
+        axutil_allocator_t *m_allocator;
+        axutil_env_t *m_env;
+};
+
+
+TEST_F(TestParser, test_axisc_1453) {
+
+    void* buffer[256];
+    axis2_char_t input1[] = "<root><![CDATA[abc&#123;def]]></root>";
+    axis2_char_t expected1[] = "<root>abc&amp;#123;def</root>";
+
+    axiom_node_t* node_input1 = axiom_node_create_from_buffer(m_env, input1);
+    ASSERT_NE(node_input1, nullptr);
+    axis2_char_t* output1 = axiom_node_to_string(node_input1, m_env);
+    ASSERT_NE(output1, nullptr);
+    ASSERT_STREQ(output1, expected1);
+
+
+    axis2_char_t input2[] = "<root><![CDATA[abc</root>def]]></root>";
+    axis2_char_t expected2[] = "<root>abc&lt;/root&gt;def</root>";
+
+    axiom_node_t* node_input2 = axiom_node_create_from_buffer(m_env, input2);
+    ASSERT_NE(node_input2, nullptr);
+    axis2_char_t* output2 = axiom_node_to_string(node_input2, m_env);
+    ASSERT_NE(output2, nullptr);
+    ASSERT_STREQ(output2, expected2);
+
+    axis2_char_t input3[] = "<root><![CDATA[]]></root>";
+    axis2_char_t expected3[] = "<root></root>";
+
+    axiom_node_t* node_input3 = axiom_node_create_from_buffer(m_env, input3);
+    ASSERT_NE(node_input3, nullptr);
+    axis2_char_t* output3 = axiom_node_to_string(node_input3, m_env);
+    ASSERT_NE(output3, nullptr);
+    ASSERT_STREQ(output3, expected3);
+
+}
diff --git a/guththila/src/guththila_xml_parser.c b/guththila/src/guththila_xml_parser.c
index 2d86511..4787662 100644
--- a/guththila/src/guththila_xml_parser.c
+++ b/guththila/src/guththila_xml_parser.c
@@ -1094,6 +1094,46 @@
                         }
                     }
                 }
+                else if ('[' == c_arra[0] && 'C' == c_arra[1])
+                {
+                    if (5 == guththila_next_no_char(m, 0, c_arra, 5, env) &&
+                        'D' == c_arra[0] && 'A' == c_arra[1] && 'T' == c_arra[2] &&
+                        'A' == c_arra[3] && '[' == c_arra[4])
+                    {
+                        /* CDATA */
+
+                        int loop_state = 1;
+                        GUTHTHILA_NEXT_CHAR(m, buffer, data_size, previous_size, env, c);
+                        GUTHTHILA_TOKEN_OPEN(m, tok, env);
+                        while(loop_state)
+                        {
+                            if (']' == c)
+                            {
+                                if (2 == guththila_next_no_char(m, 0, c_arra, 2, env) &&
+                                        ']' == c_arra[0])
+                                {
+                                    if ('>' == c_arra[1])
+                                    {
+                                        m->next = m->next - 2;
+                                        guththila_token_close(m, tok, _char_data, 0, env);
+                                        m->next = m->next + 2;
+                                        loop_state = 0;
+                                        m->guththila_event = GUTHTHILA_CHARACTER;
+                                        return GUTHTHILA_CHARACTER;
+                                    }
+                                }
+                            }
+                            if (-1 == c) {
+                                return -1;
+                            }
+                            GUTHTHILA_NEXT_CHAR(m, buffer, data_size, previous_size, env, c);
+                        }
+                    }
+                    else
+                    {
+                        return -1;
+                    }
+                }
                 else
                 {
                     GUTHTHILA_NEXT_CHAR(m, buffer, data_size, previous_size, env, c);
@@ -1452,7 +1492,11 @@
     if(m->value)
     {
         GUTHTHILA_TOKEN_TO_STRING(m->value, str, env);
-        guththila_string_evaluate_references(str, GUTHTHILA_TOKEN_LEN(m->value));
+        /* don't eval references in comments or cdata sections */
+        if (m->value->type != _char_data)
+        {
+            guththila_string_evaluate_references(str, GUTHTHILA_TOKEN_LEN(m->value));
+        }
         return str;
     }
     return NULL;