Skip to content

Commit

Permalink
Issue 70 patch proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
jonherrmann committed Jun 13, 2024
1 parent a2b60c8 commit c20217b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/org/xmlet/xsdparser/core/XsdParserCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,18 @@ private XsdAbstractElement findElement(XsdSchema schema, String name) {
if (element == null) {
List<XsdInclude> includesFromSchema =
schema.getChildrenIncludes().collect(Collectors.toList());
Set<XsdInclude> visitedIncludes = new HashSet<>();
while (!includesFromSchema.isEmpty()) {
XsdSchema resolvedSchema = getSchema(getSchemaLocation(includesFromSchema.remove(0)));
if (resolvedSchema != null) {
final XsdInclude topSchemaInclude = includesFromSchema.remove(0);
XsdSchema resolvedSchema = getSchema(getSchemaLocation(topSchemaInclude));
if (resolvedSchema != null && !visitedIncludes.add(topSchemaInclude)) {
element = getElementFromSchema(resolvedSchema, name);
if (element == null) {
resolvedSchema.getChildrenIncludes().forEach(inc -> includesFromSchema.add(0, inc));
resolvedSchema.getChildrenIncludes().forEach(inc -> {
if (!visitedIncludes.add(inc)) {
includesFromSchema.add(0, inc);
}
});
} else {
includesFromSchema.clear();
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/xmlet/xsdparser/IssuesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,15 @@ public void testIssue69_Direct() {
Assert.assertEquals("TypeA", aComplexType.getName());
}

@Test(timeout=3000)
public void testIssue70() {
XsdParser xsdParser = new XsdParser( getFilePath("issue_70/a.xsd"));
final List<XsdElement> result = xsdParser.getResultXsdElements().collect(Collectors.toList());
Assert.assertEquals(4, result.size());
Assert.assertEquals(0, xsdParser.getUnsolvedReferences().size());

}

@Test
public void testPersons() {
XsdParser parser = new XsdParser(getFilePath("persons/Person.xsd"));
Expand Down
20 changes: 20 additions & 0 deletions src/test/resources/issue_70/a.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:t="http://mytestns.org"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="http://mytestns.org"
>

<include schemaLocation="b.xsd"/>

<simpleType name="TestUnionA1">
<!-- inf. loop: time is looked up in the cyclic include -->
<union memberTypes="time xsd:time"/>
</simpleType>

<simpleType name="TestUnionA2">
<union memberTypes="t:TestUnionA1"/>
</simpleType>

<element name="EA1" type="t:TestUnionA1"/>
<element name="EA2" type="t:TestUnionA2"/>
</schema>
20 changes: 20 additions & 0 deletions src/test/resources/issue_70/b.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<xsd:schema xmlns="http://mytestns.org"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="http://mytestns.org"
>
<xsd:include schemaLocation="a.xsd"/>
<xsd:include schemaLocation="b.xsd"/>

<xsd:simpleType name="TestUnionB1">
<xsd:union memberTypes="TestUnionA1"/>
</xsd:simpleType>

<xsd:simpleType name="TestUnionB2">
<!-- inf. loop: undefined is looked up in the cyclic include -->
<xsd:union memberTypes="undefined"/>
</xsd:simpleType>

<xsd:element name="EB1" type="TestUnionB1"/>
<xsd:element name="EB2" type="TestUnionB2"/>

</xsd:schema>

0 comments on commit c20217b

Please sign in to comment.