Author: amassari
Date: Mon Aug 19 08:03:01 2013
New Revision: 1515307

URL: http://svn.apache.org/r1515307
Log:
When matching an XPath expression that is an union of several XPaths, keep 
track of the location where each part has been matched; one of the parts could 
match inside the subtree where another one has already matched, and we would 
not record it (XERCESC-2017)

Added:
    xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/
    xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test.xml
    xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test.xsd
    xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test2.xml
Modified:
    xerces/c/trunk/src/xercesc/validators/schema/identity/IC_Selector.cpp
    xerces/c/trunk/src/xercesc/validators/schema/identity/IC_Selector.hpp
    xerces/c/trunk/src/xercesc/validators/schema/identity/XPathMatcher.hpp
    xerces/c/trunk/tests/src/XSTSHarness/regression/Xerces.testSet

Modified: xerces/c/trunk/src/xercesc/validators/schema/identity/IC_Selector.cpp
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/validators/schema/identity/IC_Selector.cpp?rev=1515307&r1=1515306&r2=1515307&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/validators/schema/identity/IC_Selector.cpp 
(original)
+++ xerces/c/trunk/src/xercesc/validators/schema/identity/IC_Selector.cpp Mon 
Aug 19 08:03:01 2013
@@ -41,10 +41,21 @@ SelectorMatcher::SelectorMatcher(XercesX
     : XPathMatcher(xpath, selector->getIdentityConstraint(), manager)
     , fInitialDepth(initialDepth)
     , fElementDepth(0)
-    , fMatchedDepth(-1)
+    , fMatchedDepth(0)
     , fSelector(selector)
     , fFieldActivator(fieldActivator)
 {
+    fMatchedDepth = (int*) fMemoryManager->allocate
+    (
+        fLocationPathSize * sizeof(int)
+    );//new int[fLocationPathSize];
+    for(XMLSize_t k = 0;k<fLocationPathSize;k++)
+        fMatchedDepth[k] = -1;
+}
+
+SelectorMatcher::~SelectorMatcher()
+{
+    fMemoryManager->deallocate(fMatchedDepth);//delete [] fMatchedDepth;
 }
 
 // ---------------------------------------------------------------------------
@@ -54,7 +65,8 @@ void SelectorMatcher::startDocumentFragm
 
     XPathMatcher::startDocumentFragment();
     fElementDepth = 0;
-    fMatchedDepth = -1;
+    for(XMLSize_t k = 0;k<fLocationPathSize;k++)
+        fMatchedDepth[k] = -1;
 }
 
 void SelectorMatcher::startElement(const XMLElementDecl& elemDecl,
@@ -68,21 +80,28 @@ void SelectorMatcher::startElement(const
     XPathMatcher::startElement(elemDecl, urlId, elemPrefix, attrList, 
attrCount, validationContext);
     fElementDepth++;
 
-    // activate the fields, if selector is matched
-    unsigned char matched = isMatched();
-    if ((fMatchedDepth == -1 && ((matched & XP_MATCHED) == XP_MATCHED))
-        || ((matched & XP_MATCHED_D) == XP_MATCHED_D)) {
-
-        IdentityConstraint* ic = fSelector->getIdentityConstraint();
-        XMLSize_t count = ic->getFieldCount();
-
-        fMatchedDepth = fElementDepth;
-        fFieldActivator->startValueScopeFor(ic, fInitialDepth);
-
-        for (XMLSize_t i = 0; i < count; i++) {
-
-            XPathMatcher* matcher = 
fFieldActivator->activateField(ic->getFieldAt(i), fInitialDepth);
-            matcher->startElement(elemDecl, urlId, elemPrefix, attrList, 
attrCount, validationContext);
+    for(XMLSize_t k = 0;k<fLocationPathSize;k++)
+    {
+        // use the match flag of each member of the union
+        unsigned char matched = 0;
+        if (((fMatched[k] & XP_MATCHED) == XP_MATCHED)
+            && ((fMatched[k] & XP_MATCHED_DP) != XP_MATCHED_DP))
+            matched = fMatched[k];
+        if ((fMatchedDepth[k] == -1 && ((matched & XP_MATCHED) == XP_MATCHED))
+            || ((matched & XP_MATCHED_D) == XP_MATCHED_D)) {
+
+            IdentityConstraint* ic = fSelector->getIdentityConstraint();
+            XMLSize_t count = ic->getFieldCount();
+
+            fMatchedDepth[k] = fElementDepth;
+            fFieldActivator->startValueScopeFor(ic, fInitialDepth);
+
+            for (XMLSize_t i = 0; i < count; i++) {
+
+                XPathMatcher* matcher = 
fFieldActivator->activateField(ic->getFieldAt(i), fInitialDepth);
+                matcher->startElement(elemDecl, urlId, elemPrefix, attrList, 
attrCount, validationContext);
+            }
+            break;
         }
     }
 }
@@ -95,11 +114,16 @@ void SelectorMatcher::endElement(const X
 
     XPathMatcher::endElement(elemDecl, elemContent, validationContext, 
actualValidator);
 
-    if (fElementDepth-- == fMatchedDepth) {
+    for(XMLSize_t k = 0;k<fLocationPathSize;k++)
+    {
+        if (fElementDepth == fMatchedDepth[k]) {
 
-        fMatchedDepth = -1;
-        fFieldActivator->endValueScopeFor(fSelector->getIdentityConstraint(), 
fInitialDepth);
+            fMatchedDepth[k] = -1;
+            
fFieldActivator->endValueScopeFor(fSelector->getIdentityConstraint(), 
fInitialDepth);
+            break;
+        }
     }
+    --fElementDepth;
 }
 
 // ---------------------------------------------------------------------------

Modified: xerces/c/trunk/src/xercesc/validators/schema/identity/IC_Selector.hpp
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/validators/schema/identity/IC_Selector.hpp?rev=1515307&r1=1515306&r2=1515307&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/validators/schema/identity/IC_Selector.hpp 
(original)
+++ xerces/c/trunk/src/xercesc/validators/schema/identity/IC_Selector.hpp Mon 
Aug 19 08:03:01 2013
@@ -95,7 +95,7 @@ public:
     // -----------------------------------------------------------------------
     //  Constructors/Destructor
     // -----------------------------------------------------------------------
-    ~SelectorMatcher() {}
+    ~SelectorMatcher();
 
     int getInitialDepth() const { return fInitialDepth; }
 
@@ -140,7 +140,7 @@ private:
     // -----------------------------------------------------------------------
     int             fInitialDepth;
     int             fElementDepth;
-    int             fMatchedDepth;
+    int*            fMatchedDepth;
     IC_Selector*    fSelector;
     FieldActivator* fFieldActivator;
 };

Modified: xerces/c/trunk/src/xercesc/validators/schema/identity/XPathMatcher.hpp
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/validators/schema/identity/XPathMatcher.hpp?rev=1515307&r1=1515306&r2=1515307&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/validators/schema/identity/XPathMatcher.hpp 
(original)
+++ xerces/c/trunk/src/xercesc/validators/schema/identity/XPathMatcher.hpp Mon 
Aug 19 08:03:01 2013
@@ -126,6 +126,7 @@ private:
     void init(XercesXPath* const xpath);
     void cleanUp();
 
+protected:
     // -----------------------------------------------------------------------
     //  Data members
     //

Added: xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test.xml
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test.xml?rev=1515307&view=auto
==============================================================================
--- xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test.xml 
(added)
+++ xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test.xml Mon 
Aug 19 08:03:01 2013
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<CONFIG xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:noNamespaceSchemaLocation="test.xsd">
+       <DBS>
+               <DB ID="D"/>
+               <VDB ID="V">
+                       <PARTS>
+                               <PART_DB ID="V1"/>
+                               <PART_DB ID="V2"/>
+                       </PARTS>
+               </VDB>
+       </DBS>
+       <HOSTS>
+               <HOST ID="host1">
+                       <DBS>
+                               <DB ID="D"/>
+                               <DB ID="V1"/>
+                               <DB ID="V2"/>
+                       </DBS>
+                       <VDBS>
+                               <DB ID="V"/>
+                       </VDBS>
+               </HOST>
+       </HOSTS>
+</CONFIG>
\ No newline at end of file

Added: xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test.xsd
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test.xsd?rev=1515307&view=auto
==============================================================================
--- xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test.xsd 
(added)
+++ xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test.xsd Mon 
Aug 19 08:03:01 2013
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
elementFormDefault="qualified">
+  <xs:element name="CONFIG">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="DBS"/>
+        <xs:element ref="HOSTS"/>
+      </xs:sequence>
+    </xs:complexType>
+       <xs:key name="DbIdKey">
+               <xs:selector xpath="./DBS/DB|./DBS/VDB|./DBS/VDB/PARTS/PART_DB" 
/>
+               <xs:field xpath="@ID" />
+       </xs:key>
+       <xs:keyref name="DbIdRef" refer="DbIdKey">
+               <xs:selector xpath="./HOSTS/HOST/DBS/DB|./HOSTS/HOST/VDBS/DB" />
+               <xs:field xpath="@ID" />
+       </xs:keyref>
+  </xs:element>
+  <xs:element name="HOSTS">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="HOST"/>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="HOST">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="DBS"/>
+        <xs:element ref="VDBS"/>
+      </xs:sequence>
+      <xs:attribute name="ID" use="required" type="xs:NCName"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="VDBS">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="DB"/>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="DBS">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element maxOccurs="unbounded" ref="DB"/>
+        <xs:element minOccurs="0" ref="VDB"/>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="VDB">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="PARTS"/>
+      </xs:sequence>
+      <xs:attribute name="ID" use="required" type="xs:NCName"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="PARTS">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element maxOccurs="unbounded" ref="PART_DB"/>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="PART_DB">
+    <xs:complexType>
+      <xs:attribute name="ID" use="required" type="xs:NCName"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="DB">
+    <xs:complexType>
+      <xs:attribute name="ID" use="required" type="xs:NCName"/>
+    </xs:complexType>
+  </xs:element>
+</xs:schema>

Added: xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test2.xml
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test2.xml?rev=1515307&view=auto
==============================================================================
--- xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test2.xml 
(added)
+++ xerces/c/trunk/tests/src/XSTSHarness/regression/XERCESC-2017/test2.xml Mon 
Aug 19 08:03:01 2013
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<CONFIG xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:noNamespaceSchemaLocation="test.xsd">
+       <DBS>
+               <DB ID="D"/>
+               <VDB ID="V">
+                       <PARTS>
+                               <PART_DB ID="V11"/>
+                               <PART_DB ID="V21"/>
+                       </PARTS>
+               </VDB>
+       </DBS>
+       <HOSTS>
+               <HOST ID="host1">
+                       <DBS>
+                               <DB ID="D"/>
+                               <DB ID="V1"/>
+                               <DB ID="V2"/>
+                       </DBS>
+                       <VDBS>
+                               <DB ID="V"/>
+                       </VDBS>
+               </HOST>
+       </HOSTS>
+</CONFIG>
\ No newline at end of file

Modified: xerces/c/trunk/tests/src/XSTSHarness/regression/Xerces.testSet
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/tests/src/XSTSHarness/regression/Xerces.testSet?rev=1515307&r1=1515306&r2=1515307&view=diff
==============================================================================
--- xerces/c/trunk/tests/src/XSTSHarness/regression/Xerces.testSet (original)
+++ xerces/c/trunk/tests/src/XSTSHarness/regression/Xerces.testSet Mon Aug 19 
08:03:01 2013
@@ -842,4 +842,25 @@
       <current status="accepted" date="2010-09-28"/>
     </instanceTest>
   </testGroup>
+  <testGroup name="XERCESC-2017">
+    <annotation>
+      <documentation>XPath selector with multiple matches stops matching in a 
subtree once one match succeeds</documentation>
+    </annotation>
+    <documentationReference 
xlink:href="https://issues.apache.org/jira/browse/XERCESC-2017"/>
+    <schemaTest name="XERCESC-2017-1">
+      <schemaDocument xlink:href="./XERCESC-2017/test.xsd"/>
+      <expected validity="valid"/>
+      <current status="accepted" date="2013-08-18"/>
+    </schemaTest>
+    <instanceTest name="XERCESC-2017-2">
+      <instanceDocument xlink:href="./XERCESC-2017/test.xml"/>
+      <expected validity="valid"/>
+      <current status="accepted" date="2013-08-18"/>
+    </instanceTest>
+    <instanceTest name="XERCESC-2017-3">
+      <instanceDocument xlink:href="./XERCESC-2017/test2.xml"/>
+      <expected validity="invalid"/>
+      <current status="accepted" date="2013-08-18"/>
+    </instanceTest>
+  </testGroup>
 </testSet>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to