Luis Rodriguez Gonzalez has proposed merging lp:~zorba-coders/zorba/bug-1181360 
into lp:zorba.

Requested reviews:
  Luis Rodriguez Gonzalez (kuraru)
  Cezar Andrei (cezar-andrei)
Related bugs:
  Bug #1181360 in Zorba: "validation leaks exception"
  https://bugs.launchpad.net/zorba/+bug/1181360

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-1181360/+merge/166890
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-1181360/+merge/166890
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml	2013-05-24 22:52:47 +0000
+++ src/diagnostics/diagnostic_en.xml	2013-05-31 20:35:39 +0000
@@ -3676,6 +3676,10 @@
     <entry key="DocNodeMultipleElements">
       <value>document node has more than one element</value>
     </entry>
+    
+    <entry key="DocNodeNoElements">
+      <value>document node doesn't contain any elements, must contain exactly one element</value>
+    </entry>
 
     <entry key="EBVNotDefSeq_5">
       <value>effective boolean value not defined for sequence of more than one item that starts with "$5"</value>

=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp	2013-05-24 22:52:47 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp	2013-05-31 20:35:39 +0000
@@ -610,6 +610,7 @@
   { "~DivisionNoINF", "division can not have +-INF dividend" },
   { "~DivisionNoNaN", "division can not involve NaN" },
   { "~DocNodeMultipleElements", "document node has more than one element" },
+  { "~DocNodeNoElements", "document node doesn't contain any elements, must contain exactly one element" },
   { "~EBVNotDefSeq_5", "effective boolean value not defined for sequence of more than one item that starts with \"$5\"" },
   { "~EffectiveBooleanValue", "effective boolean value" },
   { "~ElementName", "element name" },

=== modified file 'src/diagnostics/pregenerated/dict_zed_keys.h'
--- src/diagnostics/pregenerated/dict_zed_keys.h	2013-05-16 22:26:07 +0000
+++ src/diagnostics/pregenerated/dict_zed_keys.h	2013-05-31 20:35:39 +0000
@@ -223,6 +223,7 @@
 #define ZED_DivisionNoINF "~DivisionNoINF"
 #define ZED_DivisionNoNaN "~DivisionNoNaN"
 #define ZED_DocNodeMultipleElements "~DocNodeMultipleElements"
+#define ZED_DocNodeNoElements "~DocNodeNoElements"
 #define ZED_EBVNotDefSeq_5 "~EBVNotDefSeq_5"
 #define ZED_EffectiveBooleanValue "~EffectiveBooleanValue"
 #define ZED_ElementName "~ElementName"

=== modified file 'src/types/schema/EventSchemaValidator.cpp'
--- src/types/schema/EventSchemaValidator.cpp	2013-04-24 21:40:21 +0000
+++ src/types/schema/EventSchemaValidator.cpp	2013-05-31 20:35:39 +0000
@@ -163,7 +163,7 @@
   StrX typeName(theSchemaValidatorFilter->getTypeName());
   StrX typeUri(theSchemaValidatorFilter->getTypeUri());
 
-  //cout << "    esv  - : getTypeQName:  " << typeName << " @ " << typeUri <<"\n"; std::cout.flush();
+  //std::cout << "    esv  - : getTypeQName:  " << typeName << " @ " << typeUri <<"\n"; std::cout.flush();
 
   store::Item_t typeQName;
   GENV_ITEMFACTORY->createQName(typeQName,

=== modified file 'src/types/schema/SchemaValidatorFilter.cpp'
--- src/types/schema/SchemaValidatorFilter.cpp	2013-04-24 21:40:21 +0000
+++ src/types/schema/SchemaValidatorFilter.cpp	2013-05-31 20:35:39 +0000
@@ -1069,7 +1069,7 @@
 
   if(fValidate || theXsiType)
   {
-    //cout << "  - getTypeQName: theElemDepth:" << theElemDepth << "\n";
+    //std::cout << "  - getTypeQName: theElemDepth:" << theElemDepth << "\n";
     if (theProcessorStipulatedTypeName && theElemDepth == 0 )
     {
       typeName = theProcessorStipulatedTypeName;
@@ -1077,6 +1077,7 @@
     else
     {
       const ElemStack::StackElem* topElem = fElemStack.topElement();
+
       DatatypeValidator *currentDV = 0;
       if(topElem->fThisElement->isDeclared() ||
          theXsiType  // this is when there is no schema import but xsiType is used
@@ -1084,7 +1085,6 @@
       {
         ComplexTypeInfo *currentTypeInfo = ((XercSchemaValidator*)fValidator)->
             getCurrentTypeInfo();
-
         if(currentTypeInfo)
         {
           typeName = currentTypeInfo->getTypeLocalName();

=== modified file 'src/types/schema/validate.cpp'
--- src/types/schema/validate.cpp	2013-05-21 21:44:25 +0000
+++ src/types/schema/validate.cpp	2013-05-31 20:35:39 +0000
@@ -52,6 +52,7 @@
 #include "context/namespace_context.h"
 
 #include "diagnostics/assert.h"
+#include "diagnostics/util_macros.h"
 #include "zorba/store_consts.h"
 
 //using namespace std;
@@ -92,7 +93,6 @@
   }
 }
 
-
 bool Validator::realValidationValue(
     store::Item_t& result,
     const store::Item_t& sourceNode,
@@ -125,6 +125,7 @@
       if ( child->isNode() &&
            child->getNodeKind() == store::StoreConsts::elementNode)
       {
+          std::cout << "The node is a elementNode" << std::endl;
         if (nr_child_elements)
         {
           throw XQUERY_EXCEPTION(
@@ -136,6 +137,15 @@
         nr_child_elements++;
       }
     }
+    // if nr_child_elements == 0 thow an error since it means there isn't any child element
+    if(nr_child_elements == 0)
+    {
+      throw XQUERY_EXCEPTION(
+        err::XQDY0061,
+        ERROR_PARAMS( ZED( DocNodeNoElements ) ),
+        ERROR_LOC( loc )
+      );
+    }
   }
 
   Schema* schema = typeManager->getSchema();
@@ -181,12 +191,12 @@
   {
   case store::StoreConsts::documentNode:
   {
-    //cout << "Validate document" << "\n"; cout.flush();
+    //std::cout << "Validate document" << "\n"; std::cout.flush();
 
     if ( validationMode == ParseConstants::val_typename )
     {
-      //cout << "Validate type: " << typeName->getLocalName()
-      //     << " @ " << typeName->getNamespace() << "\n"; cout.flush();
+      //std::cout << "Validate type: " << typeName->getLocalName()
+      //     << " @ " << typeName->getNamespace() << "\n"; std::cout.flush();
       schemaValidator.startType(typeName);
     }
     else
@@ -494,9 +504,9 @@
   {
     if ( child->isNode() )
     {
-      //cout << "  > child: " << (long)child->getNodeKind() << " " <<
-      //  //(child->getType() != NULL ? child->getType()->getLocalName() : "type_NULL" ) <<
-      //  "\n"; cout.flush();
+      //std::cout << "  > child: " << (long)child->getNodeKind() << " " <<
+      //  (child->getType() != NULL ? child->getType()->getLocalName() : "type_NULL" ) <<
+      //  "\n"; std::cout.flush();
 
       switch ( child->getNodeKind() )
       {
@@ -573,7 +583,7 @@
       break;
 
       case store::StoreConsts::anyNode:
-        //cout << "     - any: " << child->getStringValue() <<"\n";cout.flush();
+        //std::cout << "     - any: " << child->getStringValue() <<"\n"; std::cout.flush();
         ZORBA_ASSERT(false);
         break;
 
@@ -671,11 +681,9 @@
     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() ),
@@ -862,7 +870,7 @@
       }
       catch(ZorbaException const& /*err*/)
       {
-        // do nothing here, the validator will throw the right error at end 
+        // do nothing here, the validator will throw the right error at end
         // elemet event call
         //std::cout << "validate.cpp: processTextValue2 '" << textValue
         // << "' err:" << err.toString() << std::endl; std::cout.flush();

-- 
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