Browse Source

Fixed a null reference exception in the XML editor that occurs if the schema references an element that is not defined.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1216 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 20 years ago
parent
commit
2b08ae8c2b
  1. 9
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionData.cs
  2. 17
      src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj
  3. 56
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/MissingSchemaElementTestFixture.cs
  4. 1
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

9
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionData.cs

@ -234,15 +234,12 @@ namespace ICSharpCode.XmlEditor @@ -234,15 +234,12 @@ namespace ICSharpCode.XmlEditor
/// </summary>
void ReadSchema(XmlReader reader)
{
try
{
try {
schema = XmlSchema.Read(reader, new ValidationEventHandler(SchemaValidation));
schema.Compile(new ValidationEventHandler(SchemaValidation));
namespaceUri = schema.TargetNamespace;
}
finally
{
} finally {
reader.Close();
}
}
@ -882,7 +879,7 @@ namespace ICSharpCode.XmlEditor @@ -882,7 +879,7 @@ namespace ICSharpCode.XmlEditor
} else {
// Abstract element?
XmlSchemaElement abstractElement = FindElement(element.RefName);
if (abstractElement.IsAbstract) {
if (abstractElement != null && abstractElement.IsAbstract) {
matchedElement = FindSubstitutionGroupElement(abstractElement.QualifiedName, name);
}
}

17
src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj

@ -14,23 +14,34 @@ @@ -14,23 +14,34 @@
<ProductVersion>8.0.50215</ProductVersion>
<StartAction>Program</StartAction>
<StartProgram>..\..\..\..\..\bin\SharpDevelop.exe</StartProgram>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>AnyCPU</PlatformTarget>
<FileAlignment>4096</FileAlignment>
<NoWarn>0618</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
<Optimize>False</Optimize>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<OutputPath>..\..\..\..\..\AddIns\AddIns\DisplayBindings\XmlEditor\</OutputPath>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>False</DebugSymbols>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<OutputPath>..\..\..\..\..\AddIns\AddIns\DisplayBindings\XmlEditor\</OutputPath>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>Full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>False</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />

56
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/MissingSchemaElementTestFixture.cs

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
using System;
using System.IO;
namespace XmlEditor.Tests.Schema
{
[TestFixture]
public class MissingSchemaElementTestFixture : SchemaTestFixtureBase
{
ICompletionData[] barElementAttributes;
public override void FixtureInit()
{
XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("root", "http://foo"));
path.Elements.Add(new QualifiedName("bar", "http://foo"));
barElementAttributes = SchemaCompletionData.GetAttributeCompletionData(path);
}
[Test]
public void BarHasOneAttribute()
{
Assert.AreEqual(1, barElementAttributes.Length, "Should have 1 attribute.");
}
protected override string GetSchema()
{
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" +
" targetNamespace=\"http://foo\"\r\n" +
" xmlns=\"http://foo\"\r\n" +
" elementFormDefault=\"qualified\">\r\n" +
"\t<xs:complexType name=\"root\">\r\n" +
"\t\t<xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n" +
"\t\t\t<xs:element ref=\"foo\"/>\r\n" +
"\t\t\t<xs:element ref=\"bar\"/>\r\n" +
"\t\t</xs:choice>\r\n" +
"\t\t<xs:attribute name=\"id\" type=\"xs:string\" use=\"required\"/>\r\n" +
"\t</xs:complexType>\r\n" +
"\t<xs:element name=\"root\" type=\"root\"/>\r\n" +
"\t<xs:complexType name=\"bar\">\r\n" +
"\t\t<xs:attribute name=\"id\" type=\"xs:string\" use=\"required\"/>\r\n" +
"\t</xs:complexType>\r\n" +
"\t<xs:element name=\"bar\" type=\"bar\"/>\r\n" +
"</xs:schema>";
}
}
}

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

@ -89,6 +89,7 @@ @@ -89,6 +89,7 @@
<Compile Include="Schema.Uri\GetUriTestFixture.cs" />
<Compile Include="Schema\AbstractElementTestFixture.cs" />
<Compile Include="Utils\SchemaIncludeTestFixtureHelper.cs" />
<Compile Include="Schema\MissingSchemaElementTestFixture.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Schema\" />

Loading…
Cancel
Save