Browse Source

Fix NullReferenceException for incorrect SubstitutionGroup in XML schema.

Handle XML schema that defines an element that uses a SubstitutionGroup
element but does not define the corresponding element.
pull/33/merge
Matt Ward 13 years ago
parent
commit
ab5982d2e0
  1. 4
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs
  2. 38
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/SubstitutionGroupTests.cs
  3. 1
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

4
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs

@ -347,7 +347,9 @@ namespace ICSharpCode.XmlEditor @@ -347,7 +347,9 @@ namespace ICSharpCode.XmlEditor
{
if (!element.SubstitutionGroup.IsEmpty) {
XmlSchemaElement substitutedElement = FindElement(element.SubstitutionGroup);
return GetElementAsComplexType(substitutedElement);
if (substitutedElement != null) {
return GetElementAsComplexType(substitutedElement);
}
}
return null;
}

38
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/SubstitutionGroupTests.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Schema
{
[TestFixture]
public class SubstitutionGroupTests : SchemaTestFixtureBase
{
string namespaceURI = "http://www.w3.org/1999/XSL/Transform";
protected override string GetSchema()
{
return
"<xs:schema " +
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"" +
" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"" +
" targetNamespace=\"http://www.w3.org/1999/XSL/Transform\"" +
" elementFormDefault=\"qualified\">\r\n" +
" <xs:element name=\"stylesheet\" substitutionGroup=\"xsl:transform\"/>\r\n" +
"</xs:schema>";
}
[Test]
public void GetChildElementCompletion_ParentElementIsSubstitutionGroupButNoCorrespondingElementInSchema_NullReferenceExceptionIsNotThrown()
{
var path = new XmlElementPath();
path.AddElement(new QualifiedName("stylesheet", namespaceURI));
XmlCompletionItemCollection items = SchemaCompletion.GetChildElementCompletion(path);
Assert.AreEqual(0, items.Count);
}
}
}

1
src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

@ -168,6 +168,7 @@ @@ -168,6 +168,7 @@
<Compile Include="Schema\SingleElementSchemaTestFixture.cs" />
<Compile Include="Schema\ElementWithAttributeSchemaTestFixture.cs" />
<Compile Include="Schema\NestedElementSchemaTestFixture.cs" />
<Compile Include="Schema\SubstitutionGroupTests.cs" />
<Compile Include="Schema\XsltSchemaTests.cs" />
<Compile Include="Schema\TwoElementSchemaTestFixture.cs" />
<Compile Include="Schema\ReferencedElementsTestFixture.cs" />

Loading…
Cancel
Save