Skip to content

Commit

Permalink
Prevent stack overflow (fixes #329)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ganss committed Jun 7, 2022
1 parent b474f8b commit cf0d266
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions XmlSchemaClassGenerator.Tests/xsd/simple/recursive.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<schema id="Exceptions"
xmlns="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://schemas.nsc.co.uk/exceptions"
xmlns:local="http://schemas.nsc.co.uk/exceptions">

<complexType name="ExceptionBase">
<attribute name="Message"/>
</complexType>

<complexType name="ArgumentNullException" >
<complexContent>
<extension base="local:ExceptionBase">
<attribute name="Argument"/>
</extension>
</complexContent>
</complexType>

<complexType name="InvalidOperationException" >
<complexContent>
<extension base="local:ExceptionBase">
<attribute name="Operation"/>
</extension>
</complexContent>
</complexType>

<complexType name="StackOverflowException" >
<complexContent>
<extension base="local:ExceptionBase">
<attribute name="Method"/>
</extension>
</complexContent>
</complexType>

<element name="Exception" type="local:ExceptionBase" abstract="true" substitutionGroup="local:Exception"/>
<element name="ArgumentNull" type="local:ArgumentNullException" substitutionGroup="local:Exception"/>
<element name="InvalidOperation" type="local:InvalidOperationException" substitutionGroup="local:Exception"/>
<element name="StackOverflow" type="local:StackOverflowException" substitutionGroup="local:Exception"/>

<element name="Exceptions">
<complexType>
<sequence>
<element minOccurs="0" maxOccurs="unbounded" ref="local:Exception"/>
</sequence>
</complexType>
</element>
</schema>
2 changes: 1 addition & 1 deletion XmlSchemaClassGenerator/ModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ private IEnumerable<Substitute> GetSubstitutedElements(XmlQualifiedName name)
{
if (SubstitutionGroups.TryGetValue(name, out var substitutes))
{
foreach (var substitute in substitutes)
foreach (var substitute in substitutes.Where(s => s.Element.QualifiedName != name))
{
yield return substitute;
foreach (var recursiveSubstitute in GetSubstitutedElements(substitute.Element.QualifiedName))
Expand Down

0 comments on commit cf0d266

Please sign in to comment.