[libxml2] Bug 582887 – problems validating complex schemas



commit d9960720775145c5e67a2a5ff1edd6dfa3a5fd38
Author: Jason Childs <oblivian users sourceforge net>
Date:   Fri Aug 7 19:01:32 2009 +0200

    Bug 582887 â?? problems validating complex schemas
    
    * xmlschemas.c: fixes the problem faced when importing the same schemas
      multiple times but from different places which is allowed
    * test/schemas/582887* result/schemas/582887*: adding the specific test
      to the regressions

 result/schemas/582887_0_0         |    1 +
 test/schemas/582887-attribute.xsd |   12 ++++++++++
 test/schemas/582887-common.xsd    |    8 +++++++
 test/schemas/582887-element.xsd   |   11 +++++++++
 test/schemas/582887_0.xml         |    7 ++++++
 test/schemas/582887_0.xsd         |   17 +++++++++++++++
 xmlschemas.c                      |   42 +++++++++++++++++++++++-------------
 7 files changed, 83 insertions(+), 15 deletions(-)
---
diff --git a/result/schemas/582887_0_0 b/result/schemas/582887_0_0
new file mode 100644
index 0000000..4ae8482
--- /dev/null
+++ b/result/schemas/582887_0_0
@@ -0,0 +1 @@
+./test/schemas/582887_0.xml validates
diff --git a/result/schemas/582887_0_0.err b/result/schemas/582887_0_0.err
new file mode 100644
index 0000000..e69de29
diff --git a/test/schemas/582887-attribute.xsd b/test/schemas/582887-attribute.xsd
new file mode 100644
index 0000000..75d7d4a
--- /dev/null
+++ b/test/schemas/582887-attribute.xsd
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
+	   xmlns="http://www.example.org/test-import-case";
+	   targetNamespace="http://www.example.org/test-import-case";>
+
+  <xs:simpleType name="test-attribute">
+    <xs:restriction base="xs:string">
+      <xs:enumeration value="this" />
+    </xs:restriction>
+  </xs:simpleType>
+
+</xs:schema>
diff --git a/test/schemas/582887-common.xsd b/test/schemas/582887-common.xsd
new file mode 100644
index 0000000..c1c385d
--- /dev/null
+++ b/test/schemas/582887-common.xsd
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
+	   xmlns="http://www.example.org/test-import-case";
+	   targetNamespace="http://www.example.org/test-import-case";>
+  <xs:include schemaLocation="./582887-element.xsd" />
+  <xs:include schemaLocation="./582887-attribute.xsd" />
+
+</xs:schema>
diff --git a/test/schemas/582887-element.xsd b/test/schemas/582887-element.xsd
new file mode 100644
index 0000000..0562021
--- /dev/null
+++ b/test/schemas/582887-element.xsd
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
+	   xmlns="http://www.example.org/test-import-case";
+	   targetNamespace="http://www.example.org/test-import-case";>
+  <xs:include schemaLocation="./582887-common.xsd" />
+
+  <xs:complexType name="test-element">
+    <xs:attribute name="test-attribute" type="test-attribute" />
+  </xs:complexType>
+  <xs:element name="test-element" type="test-element" />
+</xs:schema>
diff --git a/test/schemas/582887_0.xml b/test/schemas/582887_0.xml
new file mode 100644
index 0000000..0a74714
--- /dev/null
+++ b/test/schemas/582887_0.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test-case xmlns="http://www.example.org/test-case";
+	   xmlns:tc="http://www.example.org/test-import-case";
+	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+	   xsi:schemaLocation="http://www.example.org/test-case ./582887-case.xsd">
+  <tc:test-element test-attribute="this" />
+</test-case>
diff --git a/test/schemas/582887_0.xsd b/test/schemas/582887_0.xsd
new file mode 100644
index 0000000..a3b175a
--- /dev/null
+++ b/test/schemas/582887_0.xsd
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
+	   xmlns:tc="http://www.example.org/test-import-case";
+	   xmlns="http://www.example.org/test-case";
+	   targetNamespace="http://www.example.org/test-case";>
+
+  <xs:import namespace="http://www.example.org/test-import-case";
+	     schemaLocation="./582887-common.xsd" />
+
+  <xs:complexType name="test-case">
+    <xs:sequence>
+      <xs:element ref="tc:test-element" />
+    </xs:sequence>
+  </xs:complexType>
+  <xs:element name="test-case" type="test-case" />
+
+</xs:schema>
diff --git a/xmlschemas.c b/xmlschemas.c
index 9050684..e621120 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -10343,27 +10343,39 @@ xmlSchemaAddSchemaDoc(xmlSchemaParserCtxtPtr pctxt,
 
     /* Did we already fetch the doc? */
     if (bkt != NULL) {
-	/* TODO: The following nasty cases will produce an error. */
 	if ((WXS_IS_BUCKET_IMPMAIN(type)) && (! bkt->imported)) {
-	    /* We included/redefined and then try to import a schema. */
+	    /*
+	    * We included/redefined and then try to import a schema,
+	    * but the new location provided for import was different.
+	    */
 	    if (schemaLocation == NULL)
 		schemaLocation = BAD_CAST "in_memory_buffer";
-	    xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
-		invokingNode, NULL,
-		"The schema document '%s' cannot be imported, since "
-		"it was already included or redefined",
-		schemaLocation, NULL);
-	    goto exit;
+	    if (!xmlStrEqual(schemaLocation,
+		bkt->schemaLocation)) {
+		xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
+		    invokingNode, NULL,
+		    "The schema document '%s' cannot be imported, since "
+		    "it was already included or redefined",
+		    schemaLocation, NULL);
+		goto exit;
+	    }
 	} else if ((! WXS_IS_BUCKET_IMPMAIN(type)) && (bkt->imported)) {
-	    /* We imported and then try to include/redefine a schema. */
+	    /*
+	    * We imported and then try to include/redefine a schema,
+	    * but the new location provided for the include/redefine
+	    * was different.
+	    */
 	    if (schemaLocation == NULL)
 		schemaLocation = BAD_CAST "in_memory_buffer";
-	    xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
-		invokingNode, NULL,
-		"The schema document '%s' cannot be included or "
-		"redefined, since it was already imported",
-		schemaLocation, NULL);
-	    goto exit;
+	    if (!xmlStrEqual(schemaLocation,
+		bkt->schemaLocation)) {
+		xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
+		    invokingNode, NULL,
+		    "The schema document '%s' cannot be included or "
+		    "redefined, since it was already imported",
+		    schemaLocation, NULL);
+		goto exit;
+	    }
 	}
     }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]