This is an automated email from the ASF dual-hosted git repository.

pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi-xmlbeans.git


The following commit(s) were added to refs/heads/trunk by this push:
     new cce95039 intersect attribute group wildcards in 
translateAttributeModel (#167)
cce95039 is described below

commit cce95039d6d3a9633f14a54c7c6bfff8a1e06618
Author: aizu-m <[email protected]>
AuthorDate: Mon Nov 16 02:12:26 2026 +0530

    intersect attribute group wildcards in translateAttributeModel (#167)
    
    A complex type's complete attribute wildcard is the intersection of its
    own anyAttribute and the wildcards of its attribute groups (XML Schema
    1.0, 3.4.2); an extension then adds the base type's wildcard by union.
    The extension path, also used for types with no derivation and for
    simpleContent extension, unioned all of them, so attributes in
    namespaces excluded by the intersection validated clean.
---
 .../impl/schema/StscComplexTypeResolver.java       | 24 +++++-
 .../AttributeGroupWildcardValidateTest.java        | 93 ++++++++++++++++++++++
 2 files changed, 113 insertions(+), 4 deletions(-)

diff --git 
a/src/main/java/org/apache/xmlbeans/impl/schema/StscComplexTypeResolver.java 
b/src/main/java/org/apache/xmlbeans/impl/schema/StscComplexTypeResolver.java
index 64babf41..a043c02f 100644
--- a/src/main/java/org/apache/xmlbeans/impl/schema/StscComplexTypeResolver.java
+++ b/src/main/java/org/apache/xmlbeans/impl/schema/StscComplexTypeResolver.java
@@ -807,6 +807,16 @@ public class StscComplexTypeResolver {
                                         SchemaType baseType, boolean extension,
                                         SchemaAttributeGroupImpl 
redefinitionFor) {
         StscState state = StscState.get();
+        // the type's own wildcards (local and from attribute groups) are 
intersected,
+        // an extension then adds the base type's wildcard by union
+        QNameSet baseWildcardSet = null;
+        int baseWildcardProcess = SchemaAttributeModel.NONE;
+        if (extension && seenAttributes == null) {
+            baseWildcardSet = result.getWildcardSet();
+            baseWildcardProcess = result.getWildcardProcess();
+            result.setWildcardSet(null);
+            result.setWildcardProcess(SchemaAttributeModel.NONE);
+        }
         if (seenAttributes == null) {
             seenAttributes = new HashSet<>();
         }
@@ -924,13 +934,11 @@ public class StscComplexTypeResolver {
                             result.setWildcardSet(wcset);
                             result.setWildcardProcess(wcprocess);
                         } else {
+                            
result.setWildcardSet(wcset.intersect(result.getWildcardSet()));
                             if (extension) {
-                                
result.setWildcardSet(wcset.union(result.getWildcardSet()));
                                 result.setWildcardProcess(wcprocess);
-                            } else {
-                                
result.setWildcardSet(wcset.intersect(result.getWildcardSet()));
-                                // keep old process
                             }
+                            // else keep old process
                         }
                         break;
                     }
@@ -995,6 +1003,14 @@ public class StscComplexTypeResolver {
             result.setWildcardSet(null);
             result.setWildcardProcess(SchemaAttributeModel.NONE);
         }
+        if (baseWildcardProcess != SchemaAttributeModel.NONE) {
+            if (result.getWildcardProcess() == SchemaAttributeModel.NONE) {
+                result.setWildcardSet(baseWildcardSet);
+                result.setWildcardProcess(baseWildcardProcess);
+            } else {
+                
result.setWildcardSet(result.getWildcardSet().union(baseWildcardSet));
+            }
+        }
     }
 
     static SchemaParticle extendContentModel(SchemaParticle baseContentModel, 
SchemaParticle extendedContentModel, XmlObject parseTree) {
diff --git a/src/test/java/misc/checkin/AttributeGroupWildcardValidateTest.java 
b/src/test/java/misc/checkin/AttributeGroupWildcardValidateTest.java
new file mode 100644
index 00000000..a5369abb
--- /dev/null
+++ b/src/test/java/misc/checkin/AttributeGroupWildcardValidateTest.java
@@ -0,0 +1,93 @@
+/*   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.
+ */
+
+package misc.checkin;
+
+import org.apache.xmlbeans.SchemaTypeLoader;
+import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlError;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class AttributeGroupWildcardValidateTest {
+
+    // the complete attribute wildcard of a type is the intersection of its own
+    // anyAttribute and those of its attribute groups; an extension adds the
+    // base type's wildcard by union
+    private static final String XSD =
+        "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' " +
+        "xmlns:t='urn:t' targetNamespace='urn:t'>" +
+        "  <xs:attributeGroup name='ab'>" +
+        "    <xs:anyAttribute namespace='urn:a urn:b' 
processContents='skip'/>" +
+        "  </xs:attributeGroup>" +
+        "  <xs:attributeGroup name='nested'>" +
+        "    <xs:attributeGroup ref='t:ab'/>" +
+        "    <xs:anyAttribute namespace='urn:b urn:c' 
processContents='skip'/>" +
+        "  </xs:attributeGroup>" +
+        "  <xs:element name='local'><xs:complexType>" +
+        "    <xs:attributeGroup ref='t:ab'/>" +
+        "    <xs:anyAttribute namespace='urn:b urn:c' 
processContents='skip'/>" +
+        "  </xs:complexType></xs:element>" +
+        "  <xs:element name='group'><xs:complexType>" +
+        "    <xs:attributeGroup ref='t:nested'/>" +
+        "  </xs:complexType></xs:element>" +
+        "  <xs:complexType name='base'>" +
+        "    <xs:anyAttribute namespace='urn:d' processContents='skip'/>" +
+        "  </xs:complexType>" +
+        "  <xs:element name='ext'><xs:complexType><xs:complexContent>" +
+        "    <xs:extension base='t:base'>" +
+        "      <xs:attributeGroup ref='t:ab'/>" +
+        "      <xs:anyAttribute namespace='urn:b urn:c' 
processContents='skip'/>" +
+        "    </xs:extension>" +
+        "  </xs:complexContent></xs:complexType></xs:element>" +
+        "</xs:schema>";
+
+    private static SchemaTypeLoader loader;
+
+    @BeforeAll
+    static void compileSchema() throws Exception {
+        loader = XmlBeans.loadXsd(new 
XmlObject[]{SchemaDocument.Factory.parse(XSD)});
+    }
+
+    @ParameterizedTest
+    @CsvSource({
+        "local, urn:a, false",
+        "local, urn:b, true",
+        "local, urn:c, false",
+        "group, urn:a, false",
+        "group, urn:b, true",
+        "group, urn:c, false",
+        "ext, urn:a, false",
+        "ext, urn:b, true",
+        "ext, urn:c, false",
+        "ext, urn:d, true",
+        "ext, urn:e, false"
+    })
+    void attributeWildcardsAreIntersected(String element, String ns, boolean 
valid) throws Exception {
+        XmlObject doc = loader.parse(
+            "<t:" + element + " xmlns:t='urn:t' xmlns:p='" + ns + "' 
p:x='1'/>", null, null);
+        List<XmlError> errors = new ArrayList<>();
+        assertEquals(valid, doc.validate(new 
XmlOptions().setErrorListener(errors)), errors.toString());
+    }
+}


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

Reply via email to