From 58a6e819c072437620d92aaba6a34efa196a3ea6 Mon Sep 17 00:00:00 2001
From: Botond Baranyi <botond.baranyi@ericsson.com>
Date: Tue, 5 Jun 2018 16:30:14 +0200
Subject: [PATCH] XML enc/dec: removed namespace checks from sub-elements of
 anyElements (bug 535558)

Change-Id: I462dd02935cac57e5da25d517e54b20514e5e2bd
Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com>
---
 core/Universal_charstring.cc                  |  5 ++-
 .../XML/EXER-whitepaper/AnyElement.ttcnpp     | 34 +++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/core/Universal_charstring.cc b/core/Universal_charstring.cc
index b80efdc39..652195798 100644
--- a/core/Universal_charstring.cc
+++ b/core/Universal_charstring.cc
@@ -1888,6 +1888,7 @@ int UNIVERSAL_CHARSTRING::XER_encode(const XERdescriptor_t& p_td,
         XmlReaderWrap checker(other_buf);
         // Walk through the XML. If it's not well-formed, XmlReaderWrap
         // will call TTCN_error => Dynamic testcase error.
+        bool top_element_checked = false;
         while (1 == checker.Read()) {
           if (checker.NodeType() == XML_READER_TYPE_ELEMENT &&
               (p_td.xer_bits & (ANY_FROM | ANY_EXCEPT))) {
@@ -1912,9 +1913,11 @@ int UNIVERSAL_CHARSTRING::XER_encode(const XERdescriptor_t& p_td,
               other_buf.set_pos(index);
               new_buf.put_s(other_buf.get_len() - index, other_buf.get_read_data());
               other_buf = new_buf;
-            } else {
+            } else if (!top_element_checked) {
+              // the namespace restrictions only apply to the top-level element
               check_namespace_restrictions(p_td, xmlns);
             }
+            top_element_checked = true;
           }
         }
           
diff --git a/regression_test/XML/EXER-whitepaper/AnyElement.ttcnpp b/regression_test/XML/EXER-whitepaper/AnyElement.ttcnpp
index a9212fe45..7c40f1e74 100644
--- a/regression_test/XML/EXER-whitepaper/AnyElement.ttcnpp
+++ b/regression_test/XML/EXER-whitepaper/AnyElement.ttcnpp
@@ -404,6 +404,37 @@ testcase decode_aes() runs on AE
   CHECK_DECODE(exer_dec_aes, str_aes_e, AEProductSingle, aesp_e);
 }
 
+
+const AEProduct aep_emb := {
+  name  := "nothing",
+  price := 1,
+  info  := "<ns:top xmlns:ns=\"http://www.example.com/A\">" &
+             "<ns1:sub1 xmlns:ns1=\"http://www.example.com/C\">100</ns1:sub1>" &
+             "<ns2:sub2 xmlns:ns2=\"http://www.somewhereelse.com\">200</ns2:sub2>" &
+           "</ns:top>"
+}
+
+const universal charstring str_ae_emb :=
+"<AEProduct>\n" &
+"\t<name>nothing</name>\n" &
+"\t<price>1</price>\n" &
+"\t<ns:top xmlns:ns=\"http://www.example.com/A\">" &
+    "<ns1:sub1 xmlns:ns1=\"http://www.example.com/C\">100</ns1:sub1>" &
+    "<ns2:sub2 xmlns:ns2=\"http://www.somewhereelse.com\">200</ns2:sub2>" &
+  "</ns:top>\n" &
+"</AEProduct>\n\n";
+
+testcase encode_ae_emb() runs on AE
+{
+  CHECK_METHOD(exer_enc_ae, aep_emb, str_ae_emb);
+}
+
+testcase decode_ae_emb() runs on AE
+{
+  CHECK_DECODE(exer_dec_ae, str_ae_emb, AEProduct, aep_emb);
+}
+
+
 control
 {
   execute(encode_ae())
@@ -423,6 +454,9 @@ control
 
   execute(encode_aes())
   execute(decode_aes())
+  
+  execute(encode_ae_emb())
+  execute(decode_ae_emb())
 }
 
 }
-- 
GitLab