Cezar Andrei has proposed merging 
lp:~zorba-coders/zorba/bug857842-textWithComment into lp:zorba.

Requested reviews:
  Cezar Andrei (cezar-andrei)
  Matthias Brantner (matthias-brantner)
Related bugs:
  Bug #857842 in Zorba: "Assertion failed with simple content element with 
comments"
  https://bugs.launchpad.net/zorba/+bug/857842

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug857842-textWithComment/+merge/103367

Fix for Bug #857842 Assertion failed with simple content element with comments
Make use of XML_SCHEMA_NS definition from ns_consts.h.

-- 
https://code.launchpad.net/~zorba-coders/zorba/bug857842-textWithComment/+merge/103367
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-04-24 12:39:38 +0000
+++ ChangeLog	2012-04-24 20:19:22 +0000
@@ -40,6 +40,7 @@
   * Fixed bug #949910 (has-children may be invoked on all nodes). Internally, zorba::store::Item::getChildren() now returns NULL on node classes without offspring (instead of raising an error).
   * Fixed Bug #933490: Error ItemFactoryImpl::createBase64Binary with istream
   * Fixed bug #867112 (Diagnostic Handler was not working on external APIs)
+  * Fixed bug #857842 (Assertion failed with simple content element with comments)
 
 
 version 2.2

=== modified file 'src/api/xmldatamanagerimpl.cpp'
--- src/api/xmldatamanagerimpl.cpp	2012-04-24 12:39:38 +0000
+++ src/api/xmldatamanagerimpl.cpp	2012-04-24 20:19:22 +0000
@@ -33,18 +33,15 @@
 #include "api/staticcontextimpl.h"
 #include "api/documentmanagerimpl.h"
 #include "api/collectionmanagerimpl.h"
-
+#include "context/static_context.h"
 #include "diagnostics/xquery_diagnostics.h"
-
+#include "runtime/util/flowctl_exception.h"
 #include "store/api/collection.h"
 #include "store/api/item.h"
-#include "system/globalenv.h"
 #include "store/api/store.h"
 #include "store/api/item_factory.h"
-
-#include "context/static_context.h"
-
-#include "runtime/util/flowctl_exception.h"
+#include "system/globalenv.h"
+#include "zorbamisc/ns_consts.h"
 
 #ifndef ZORBA_NO_FULL_TEXT
 #include "stemmer_wrapper.h"
@@ -292,7 +289,7 @@
     Item empty_item;
     Item validated_options;
     NsBindings nsPairs;
-    Item untyped_type = theFactory->createQName("http://www.w3.org/2001/XMLSchema";, "xs", "untyped");
+    Item untyped_type = theFactory->createQName(XML_SCHEMA_NS, XML_SCHEMA_PREFIX, "untyped");
     Item options_node = theFactory->createElementNode(empty_item,
         theFactory->createQName(static_context::ZORBA_XML_FN_OPTIONS_NS, "options"),
         untyped_type, false, false, nsPairs);
@@ -340,7 +337,7 @@
     Item empty_item;
     Item validated_options;
     NsBindings nsPairs;
-    Item untyped_type = theFactory->createQName("http://www.w3.org/2001/XMLSchema";, "xs", "untyped");
+    Item untyped_type = theFactory->createQName(XML_SCHEMA_NS, XML_SCHEMA_PREFIX, "untyped");
     Item options_node = theFactory->createElementNode(empty_item,
         theFactory->createQName(static_context::ZORBA_XML_FN_OPTIONS_NS, "options"),
         untyped_type, false, false, nsPairs);

=== modified file 'src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp'
--- src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp	2012-04-24 12:39:38 +0000
+++ src/compiler/parsetree/parsenode_print_xqdoc_visitor.cpp	2012-04-24 20:19:22 +0000
@@ -38,6 +38,8 @@
 #include "store/api/iterator.h"
 
 #include "system/globalenv.h"
+#include "zorbamisc/ns_consts.h"
+
 
 using namespace std;
 
@@ -499,10 +501,10 @@
   theVersion("1.0"),
   theFactory(GENV_ITEMFACTORY)
 {
-  theNamespaceMap["fn"] = "http://www.w3.org/2005/xpath-functions";;
-  theNamespaceMap[""] = "http://www.w3.org/2005/xpath-functions";;
-  theNamespaceMap["xs"] = "http://www.w3.org/2001/XMLSchema";;
-  theNamespaceMap["local"] = "http://www.w3.org/2005/xquery-local-functions";;
+  theNamespaceMap["fn"] = XQUERY_XPATH_FN_NS;
+  theNamespaceMap[""] = XQUERY_XPATH_FN_NS;
+  theNamespaceMap[XML_SCHEMA_PREFIX] = XML_SCHEMA_NS;
+  theNamespaceMap["local"] = XQUERY_LOCAL_FN_NS;
 }
 
 

=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp	2012-04-24 12:39:38 +0000
+++ src/compiler/translator/translator.cpp	2012-04-24 20:19:22 +0000
@@ -83,6 +83,7 @@
 
 #include "zorbatypes/URI.h"
 #include "zorbatypes/numconversions.h"
+#include "zorbamisc/ns_consts.h"
 
 #ifdef ZORBA_WITH_DEBUGGER
 #include "debugger/debugger_commons.h"
@@ -105,7 +106,6 @@
 
 
 #define NODE_SORT_OPT
-#define XS_URI "http://www.w3.org/2001/XMLSchema";
 
 namespace zorba
 {
@@ -2011,7 +2011,7 @@
       theSctx->bind_ns(pfx, targetNS, loc, err::XQST0033);
   }
 
-  zstring xsdTNS = zstring(XS_URI);
+  zstring xsdTNS = zstring(XML_SCHEMA_NS);
   if ( xsdTNS.compare(targetNS)==0 )
   {
     // Xerces doesn't like importing XMLSchema.xsd schema4schema, so we skip it

=== modified file 'src/runtime/strings/strings_impl.cpp'
--- src/runtime/strings/strings_impl.cpp	2012-04-24 12:39:38 +0000
+++ src/runtime/strings/strings_impl.cpp	2012-04-24 20:19:22 +0000
@@ -1840,7 +1840,7 @@
   store::NsBindings   ns_binding;
   zstring baseURI;
   GENV_ITEMFACTORY->createQName(untyped_type_name,
-                                "http://www.w3.org/2001/XMLSchema";, "xs", "untyped");
+                                XML_SCHEMA_NS, XML_SCHEMA_PREFIX, "untyped");
   GENV_ITEMFACTORY->createQName(non_match_element_name,
                                 static_context::W3C_FN_NS, "fn", "non-match");
   GENV_ITEMFACTORY->createElementNode(non_match_elem, parent, non_match_element_name, untyped_type_name, false, false, ns_binding, baseURI);
@@ -1969,7 +1969,7 @@
   store::NsBindings   ns_binding;
   zstring baseURI;
   GENV_ITEMFACTORY->createQName(untyped_type_name,
-                                "http://www.w3.org/2001/XMLSchema";, "xs", "untyped");
+                                XML_SCHEMA_NS, XML_SCHEMA_PREFIX, "untyped");
   GENV_ITEMFACTORY->createQName(match_element_name,
                                 static_context::W3C_FN_NS, "fn", "match");
   store::Item_t match_elem;
@@ -2129,7 +2129,7 @@
     store::NsBindings   ns_binding;
     zstring baseURI;
     GENV_ITEMFACTORY->createQName(untyped_type_name,
-                                  "http://www.w3.org/2001/XMLSchema";, "xs", "untyped");
+                                  XML_SCHEMA_NS, XML_SCHEMA_PREFIX, "untyped");
     GENV_ITEMFACTORY->createQName(result_element_name,
                                   static_context::W3C_FN_NS, "fn", "analyze-string-result");
     GENV_ITEMFACTORY->createElementNode(result, NULL, result_element_name, untyped_type_name, false, false, ns_binding, baseURI);

=== modified file 'src/types/root_typemanager.cpp'
--- src/types/root_typemanager.cpp	2012-04-24 12:39:38 +0000
+++ src/types/root_typemanager.cpp	2012-04-24 20:19:22 +0000
@@ -20,16 +20,18 @@
 #include <zorba/identtypes.h>
 #include <zorba/typeident.h>
 
-#include "zorbatypes/datetime.h"
-#include "zorbatypes/duration.h"
+#include "store/api/item_factory.h"
+#include "store/api/store.h"
 
 #include "system/globalenv.h"
 
 #include "types/root_typemanager.h"
 #include "types/node_test.h"
 
-#include "store/api/item_factory.h"
-#include "store/api/store.h"
+#include "zorbamisc/ns_consts.h"
+
+#include "zorbatypes/datetime.h"
+#include "zorbatypes/duration.h"
 
 
 
@@ -200,14 +202,11 @@
   TypeManagerImpl(NULL),
   m_atomic_qnametype_map(ATOMIC_QNAMETYPE_MAP_SIZE, false)
 {
-#define XS_URI "http://www.w3.org/2001/XMLSchema";
-#define XS_PREFIX "xs"
-
 #define ZXSE_URI "http://www.zorba-xquery.com/zorba/schema-extensions";
 #define ZXSE_PREFIX "zxse"
 
 #define XSQNDECL(var, local)  \
-  GENV.getStore().getItemFactory()->createQName(var, XS_URI, XS_PREFIX, local)
+  GENV.getStore().getItemFactory()->createQName(var, XML_SCHEMA_NS, XML_SCHEMA_PREFIX, local)
 
   XSQNDECL(XS_ANY_ATOMIC_QNAME, "anyAtomicType");
   XSQNDECL(XS_STRING_QNAME, "string");

=== modified file 'src/types/schema/validate.cpp'
--- src/types/schema/validate.cpp	2012-04-24 12:39:38 +0000
+++ src/types/schema/validate.cpp	2012-04-24 20:19:22 +0000
@@ -473,6 +473,8 @@
     const QueryLoc& loc)
 {
   store::Item_t child;
+  bool hasTextNode = false;
+  zstring textNodeValue = zstring("");
 
   while ( children->next(child) )
   {
@@ -485,6 +487,13 @@
       switch ( child->getNodeKind() )
       {
       case store::StoreConsts::elementNode:
+        if (hasTextNode)
+        {
+          finishTextNode(sctx, typeManager, schemaValidator, parent,
+                         textNodeValue, loc);
+          textNodeValue = "";
+          hasTextNode = false;
+        }
         processElement(sctx, typeManager, schemaValidator, parent, child, loc);
         break;
 
@@ -498,94 +507,11 @@
 
       case store::StoreConsts::textNode:
       {
+        // keep on adding the text
+        hasTextNode = true;
         zstring childStringValue;
         child->getStringValue2(childStringValue);
-        schemaValidator.text(childStringValue);
-
-        store::Item_t typeQName = schemaValidator.getTypeQName();
-
-        store::Item_t validatedTextNode;
-
-        TypeIdentifier_t typeIdentifier =
-          TypeIdentifier::createNamedType(
-            Unmarshaller::newString( typeQName->getNamespace() ),
-            Unmarshaller::newString( typeQName->getLocalName() )
-          );
-
-        //xqType is NULL, create_type can't find it
-        xqtref_t xqType = typeManager->create_type(*typeIdentifier);
-
-#if 0   // enable this to debug children values
-        if ( typeQName.getp() && xqType.getp() )
-        {
-          cout << "     - text: '" << childStringValue << "' T: " <<
-            typeQName->getLocalName() << "\n"; cout.flush();
-          cout << "        xqT: " << xqType->toString() << "  content_kind: " <<
-            (long)xqType->content_kind() << " tKind:" << (long)xqType->type_kind() << " \n";
-          cout.flush();
-        }
-        else
-          cout << "     - text2: '" << childStringValue << "' tQN: " <<
-            (typeQName ? typeQName->getStringValue() : "NULL") <<
-            " xqT:" << ( xqType.getp() ? xqType.getp()->toString() : "NULL" )
-               << "\n"; cout.flush();
-#endif
-
-        if ( xqType != NULL &&
-             xqType->content_kind() == XQType::SIMPLE_CONTENT_KIND )
-        {
-          store::NsBindings nsBindings;
-          parent->getNamespaceBindings(nsBindings);
-          std::vector<store::Item_t> typedValues;
-          
-          processTextValue(sctx,
-                           typeManager,
-                           nsBindings,
-                           typeQName,
-                           childStringValue,
-                           typedValues,
-                           loc);
-
-          if ( typedValues.size() == 1 ) // hack around serialization bug
-            GENV_ITEMFACTORY->createTextNode(validatedTextNode, parent,
-                                             typedValues[0]);
-          else
-            GENV_ITEMFACTORY->createTextNode(validatedTextNode, parent,
-                                             typedValues);
-        }
-        else if ( xqType!=NULL &&
-                  (xqType->content_kind()==XQType::ELEMENT_ONLY_CONTENT_KIND ||
-                   xqType->content_kind()==XQType::EMPTY_CONTENT_KIND ))
-        {
-          // if text not valid the schemaValidator should have already
-          // thrown an error
-
-          // XQ XP Datamodel Spec: http://www.w3.org/TR/xpath-datamodel/
-          // section 6.7.4 Construction from a PSVI
-          if ( !utf8::is_whitespace(childStringValue) )
-          {
-            zstring empty;
-            GENV_ITEMFACTORY->createTextNode(validatedTextNode,
-                                             parent,
-                                             empty);
-            //cout << "      -- create empty text : ElementOnly || Empty" << endl;
-          }
-          else 
-          {
-            //cout << "      -- skip this text: (ElemOnly || Empty) && whitespace" << endl;
-          }
-        }
-        else
-          //if ( xqType!=NULL &&
-          //     xqType->content_kind()==XQType::MIXED_CONTENT_KIND )
-        {
-          // if text not valid the schemaValidator should have already
-          // thrown an error
-          GENV_ITEMFACTORY->createTextNode(validatedTextNode,
-                                           parent,
-                                           childStringValue);
-          //cout << "      -- create empty text: Mixed" << endl;
-        }
+        textNodeValue += childStringValue;
       }
       break;
 
@@ -607,7 +533,7 @@
       case store::StoreConsts::commentNode:
       {
         //cout << "     - comment: " << child->getStringValue() <<
-        //"\n"; cout.flush();
+        //        "\n"; cout.flush();
         store::Item_t commentNode;
         zstring childStringValue;
         child->getStringValue2(childStringValue);
@@ -625,7 +551,112 @@
       }
     }
   }
-}
+
+  if (hasTextNode)
+  {
+    finishTextNode(sctx, typeManager, schemaValidator, parent,
+                   textNodeValue, loc);
+    textNodeValue = "";
+    hasTextNode = false;
+  }
+}
+
+void Validator::finishTextNode(
+    const static_context* sctx,
+    TypeManager* typeManager,
+    EventSchemaValidator& schemaValidator,
+    store::Item* parent,
+    zstring textNodeValue,
+    const QueryLoc& loc)
+{
+  schemaValidator.text(textNodeValue);
+
+  store::Item_t typeQName = schemaValidator.getTypeQName();
+
+  store::Item_t validatedTextNode;
+
+  TypeIdentifier_t typeIdentifier =
+    TypeIdentifier::createNamedType(
+      Unmarshaller::newString( typeQName->getNamespace() ),
+      Unmarshaller::newString( typeQName->getLocalName() )
+    );
+
+  //xqType is NULL, create_type can't find it
+  xqtref_t xqType = typeManager->create_type(*typeIdentifier);
+
+#if 0   // enable this to debug children values
+  if ( typeQName.getp() && xqType.getp() )
+  {
+    cout << "     - text: '" << textNodeValue << "' T: " <<
+      typeQName->getLocalName() << "\n"; cout.flush();
+    cout << "        xqT: " << xqType->toString() << "  content_kind: " <<
+      (long)xqType->content_kind() << " tKind:" << (long)xqType->type_kind() << " \n";
+    cout.flush();
+  }
+  else
+    cout << "     - text2: '" << textNodeValue << "' tQN: " <<
+      (typeQName ? typeQName->getStringValue() : "NULL") <<
+      " xqT:" << ( xqType.getp() ? xqType.getp()->toString() : "NULL" )
+         << "\n"; cout.flush();
+#endif
+
+  if ( xqType != NULL &&
+       xqType->content_kind() == XQType::SIMPLE_CONTENT_KIND )
+  {
+    store::NsBindings nsBindings;
+    parent->getNamespaceBindings(nsBindings);
+    std::vector<store::Item_t> typedValues;
+
+    processTextValue(sctx,
+                     typeManager,
+                     nsBindings,
+                     typeQName,
+                     textNodeValue,
+                     typedValues,
+                     loc);
+
+    if ( typedValues.size() == 1 ) // hack around serialization bug
+      GENV_ITEMFACTORY->createTextNode(validatedTextNode, parent,
+                                       typedValues[0]);
+    else
+      GENV_ITEMFACTORY->createTextNode(validatedTextNode, parent,
+                                       typedValues);
+  }
+  else if ( xqType!=NULL &&
+            (xqType->content_kind()==XQType::ELEMENT_ONLY_CONTENT_KIND ||
+             xqType->content_kind()==XQType::EMPTY_CONTENT_KIND ))
+  {
+    // if text not valid the schemaValidator should have already
+    // thrown an error
+
+    // XQ XP Datamodel Spec: http://www.w3.org/TR/xpath-datamodel/
+    // section 6.7.4 Construction from a PSVI
+    if ( !utf8::is_whitespace(textNodeValue) )
+    {
+      zstring empty;
+      GENV_ITEMFACTORY->createTextNode(validatedTextNode,
+                                       parent,
+                                       empty);
+      //cout << "      -- create empty text : ElementOnly || Empty" << endl;
+    }
+    else
+    {
+      //cout << "      -- skip this text: (ElemOnly || Empty) && whitespace" << endl;
+    }
+  }
+  else
+    //if ( xqType!=NULL &&
+    //     xqType->content_kind()==XQType::MIXED_CONTENT_KIND )
+  {
+    // if text not valid the schemaValidator should have already
+    // thrown an error
+    GENV_ITEMFACTORY->createTextNode(validatedTextNode,
+                                     parent,
+                                     textNodeValue);
+    //cout << "      -- create empty text: Mixed" << endl;
+  }
+}
+
 
 
 void Validator::processNamespaces (

=== modified file 'src/types/schema/validate.h'
--- src/types/schema/validate.h	2012-04-24 12:39:38 +0000
+++ src/types/schema/validate.h	2012-04-24 20:19:22 +0000
@@ -117,6 +117,14 @@
         store::Iterator_t children,
         const QueryLoc& loc);
 
+  static void finishTextNode(
+    const static_context* sctx,
+    TypeManager* typeManager,
+    EventSchemaValidator& schemaValidator,
+    store::Item* parent,
+    zstring textNodeValue,
+    const QueryLoc& loc);
+
   static store::Item_t processElement(
         const static_context* sctx,
         TypeManager* typeManager, 

=== modified file 'src/util/http_util.cpp'
--- src/util/http_util.cpp	2012-04-24 12:39:38 +0000
+++ src/util/http_util.cpp	2012-04-24 20:19:22 +0000
@@ -23,6 +23,7 @@
 #include <api/unmarshaller.h>
 #include "http_util.h"
 #include "error_util.h"
+#include "zorbamisc/ns_consts.h"
 
 
 namespace zorba {
@@ -51,10 +52,10 @@
     Item lNodeName = lFactory->createQName("http://expath.org/ns/http-client";, "http", "request");
     Item lEmptyItem;
     NsBindings nsPairs;
-    nsPairs.push_back(std::make_pair(String("xs"), String("http://www.w3.org/2001/XMLSchema";)));
+    nsPairs.push_back(std::make_pair(String(XML_SCHEMA_PREFIX), String(XML_SCHEMA_NS)));
     Item lRequestElement = lFactory->createElementNode(lEmptyItem, lNodeName,
-                                                       lFactory->createQName("http://www.w3.org/2001/XMLSchema";,
-                                                                             "xs", "untyped"),
+                                                       lFactory->createQName(XML_SCHEMA_NS,
+                                                                             XML_SCHEMA_PREFIX, "untyped"),
                                                        true, false, nsPairs);
     lFactory->createAttributeNode(lRequestElement, lFactory->createQName("", "method"), Item(), lFactory->createString("GET"));
     lFactory->createAttributeNode(lRequestElement, lFactory->createQName("", "href"), Item(), lFactory->createString(theUri.c_str()));

=== modified file 'src/zorbamisc/ns_consts.h'
--- src/zorbamisc/ns_consts.h	2012-04-24 12:39:38 +0000
+++ src/zorbamisc/ns_consts.h	2012-04-24 20:19:22 +0000
@@ -31,9 +31,11 @@
 
 #define XML_NS                  W3C_NS "XML/1998/namespace"
 #define XML_SCHEMA_NS           W3C_NS "2001/XMLSchema"
+#define XML_SCHEMA_PREFIX       "xs"
 
 #define XQUERY_ERR_NS           W3C_NS "2005/xqt-errors"                //not predeclared in XQuery 3.0
 #define XQUERY_LOCAL_FN_NS      W3C_NS "2005/xquery-local-functions"
+#define XQUERY_XPATH_FN_NS      W3C_NS "2005/xpath-functions"
 #define XQUERY_MATH_FN_NS       W3C_NS "2005/xpath-functions/math"      //not predeclared in XQuery 3.0
 
 #define XSI_NS                  W3C_NS "2001/XMLSchema-instance"

=== modified file 'src/zorbaserialization/serialize_zorba_types.cpp'
--- src/zorbaserialization/serialize_zorba_types.cpp	2012-04-24 12:39:38 +0000
+++ src/zorbaserialization/serialize_zorba_types.cpp	2012-04-24 20:19:22 +0000
@@ -35,6 +35,8 @@
 #include "store/api/item_factory.h"
 //#include "store/api/tuples.h"
 
+#include "zorbamisc/ns_consts.h"
+
 #include "zorbatypes/datetime.h"
 #include "zorbatypes/collation_manager.h"
 #include "zorbatypes/integer.h"
@@ -455,7 +457,7 @@
         type = obj->getType();
         name_of_type = type->getLocalName();
         const zstring& ns =type->getNamespace();
-        is_qname = (name_of_type == "QName" && ns == "http://www.w3.org/2001/XMLSchema";);
+        is_qname = (name_of_type == "QName" && ns == XML_SCHEMA_NS);
       }
 
       ar & is_qname;
@@ -484,7 +486,7 @@
       }
       else if (!ar.is_serializing_out())
       {
-        GENV_ITEMFACTORY->createQName(type, "http://www.w3.org/2001/XMLSchema";, "xs", "QName");
+        GENV_ITEMFACTORY->createQName(type, XML_SCHEMA_NS, XML_SCHEMA_PREFIX, "QName");
       }
 
       if(!ar.is_serializing_out())
@@ -982,7 +984,7 @@
       //  store::simplestore::ElementNode *elem_node = dynamic_cast<store::simplestore::ElementNode*>(obj);
       //  haveTypedValue = elem_node->haveTypedValue();
       //  haveEmptyValue = elem_node->haveEmptyValue();
-        if(!ZSTREQ(name_of_type->getNamespace(), "http://www.w3.org/2001/XMLSchema";) ||
+        if(!ZSTREQ(name_of_type->getNamespace(), XML_SCHEMA_NS) ||
            !ZSTREQ(name_of_type->getLocalName(), "untyped"))
           haveTypedValue = true;
       }

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to