Browse Source

Fixed null reference exception that occurs when attempting to go to the schema definition inside an empty start tag followed by a newline and then spaces.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3002 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 18 years ago
parent
commit
4339fffef0
  1. 6
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs
  2. 25
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/ActiveElementStartPathTestFixture.cs

6
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs

@ -446,6 +446,7 @@ namespace ICSharpCode.XmlEditor @@ -446,6 +446,7 @@ namespace ICSharpCode.XmlEditor
int elementStartIndex = -1;
int currentIndex = index - 1;
for (int i = 0; i < index; ++i) {
char currentChar = xml[currentIndex];
@ -660,7 +661,10 @@ namespace ICSharpCode.XmlEditor @@ -660,7 +661,10 @@ namespace ICSharpCode.XmlEditor
elementEndIndex = xml.IndexOf(' ', elementStartIndex);
}
if (elementEndIndex >= elementStartIndex) {
return xml.Substring(elementStartIndex, elementEndIndex - elementStartIndex);
string elementName = xml.Substring(elementStartIndex, elementEndIndex - elementStartIndex).Trim();
if (elementName.Length > 1) {
return elementName;
}
}
}
return null;

25
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/ActiveElementStartPathTestFixture.cs

@ -111,5 +111,30 @@ namespace XmlEditor.Tests.Parser @@ -111,5 +111,30 @@ namespace XmlEditor.Tests.Parser
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
Assert.AreEqual(0, elementPath.Elements.Count, "Should have no path.");
}
/// <summary>
/// If the user has entered just the opening tag and then tries to go to the schema definition of the active
/// element the XmlParser throws a null exception. The user is also not indenting the xml with tabs but
/// spaces. This test fixture tests checks for that bug. Note at the bug does not appear if the xml is indented with
/// tabs.
/// </summary>
[Test]
public void EmptyElement()
{
string xml = "<Page>\r\n" +
" <Grid><\r\n" + // Cursor position is after the opening tag < at the end of this line.
" </Grid>\r\n" +
"</Page>";
string textToFind = "<Grid><";
int index = xml.IndexOf(textToFind) + textToFind.Length;
// Sanity check that the index position is correct.
Assert.AreEqual('\r', xml[index]);
Assert.AreEqual('<', xml[index - 1]);
XmlElementPath path = XmlParser.GetActiveElementStartPathAtIndex(xml, index);
Assert.AreEqual(0, path.Elements.Count, "Should be no elements since there is no element at the index.");
}
}
}

Loading…
Cancel
Save