Browse Source

Added empty string checks to XmlParser.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3960 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
c773c2e393
  1. 12
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs
  2. 25
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeNameTestFixture.cs
  3. 6
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/InsideAttributeValueTestFixture.cs
  4. 6
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/NamespaceDeclarationTestFixture.cs

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

@ -118,7 +118,7 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public static bool IsNamespaceDeclaration(string xml, int index) public static bool IsNamespaceDeclaration(string xml, int index)
{ {
if (xml.Length == 0) { if (String.IsNullOrEmpty(xml)) {
return false; return false;
} }
@ -185,7 +185,7 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public static string GetAttributeName(string xml, int index) public static string GetAttributeName(string xml, int index)
{ {
if (xml.Length == 0) { if (String.IsNullOrEmpty(xml)) {
return String.Empty; return String.Empty;
} }
@ -203,7 +203,7 @@ namespace ICSharpCode.XmlEditor
{ {
string name = GetAttributeNameAtIndex(xml, index); string name = GetAttributeNameAtIndex(xml, index);
QualifiedName qualifiedName = GetQualifiedName(name); QualifiedName qualifiedName = GetQualifiedName(name);
if (String.IsNullOrEmpty(qualifiedName.Namespace) && includeNamespace) { if (qualifiedName != null && String.IsNullOrEmpty(qualifiedName.Namespace) && includeNamespace) {
QualifiedNameCollection namespaces = new QualifiedNameCollection(); QualifiedNameCollection namespaces = new QualifiedNameCollection();
XmlElementPath path = GetActiveElementStartPathAtIndex(xml, index, namespaces); XmlElementPath path = GetActiveElementStartPathAtIndex(xml, index, namespaces);
qualifiedName.Namespace = GetNamespaceForPrefix(namespaces, path.Elements.LastPrefix); qualifiedName.Namespace = GetNamespaceForPrefix(namespaces, path.Elements.LastPrefix);
@ -226,6 +226,10 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public static string GetAttributeNameAtIndex(string xml, int index) public static string GetAttributeNameAtIndex(string xml, int index)
{ {
if (String.IsNullOrEmpty(xml)) {
return String.Empty;
}
index = GetCorrectedIndex(xml.Length, index); index = GetCorrectedIndex(xml.Length, index);
bool ignoreWhitespace = true; bool ignoreWhitespace = true;
@ -308,7 +312,7 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public static bool IsInsideAttributeValue(string xml, int index) public static bool IsInsideAttributeValue(string xml, int index)
{ {
if (xml.Length == 0) { if (String.IsNullOrEmpty(xml)) {
return false; return false;
} }

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

@ -114,6 +114,31 @@ namespace XmlEditor.Tests.Parser
QualifiedName name = XmlParser.GetQualifiedAttributeName(text, text.Length); QualifiedName name = XmlParser.GetQualifiedAttributeName(text, text.Length);
Assert.AreEqual(expectedName, name); Assert.AreEqual(expectedName, name);
} }
[Test]
public void GetQualifiedAttributeNameWithEmptyString()
{
Assert.IsNull(XmlParser.GetQualifiedAttributeNameAtIndex(String.Empty, 0, true));
}
[Test]
public void GetAttributeNameAtIndexWithNullString()
{
Assert.AreEqual(String.Empty, XmlParser.GetAttributeNameAtIndex(null, 0));
}
[Test]
public void GetAttributeNameWithNullString()
{
Assert.AreEqual(String.Empty, XmlParser.GetAttributeName(null, 0));
}
[Test]
public void GetQualifiedAttributeNameWithSingleXmlCharacter()
{
Assert.IsNull(XmlParser.GetQualifiedAttributeNameAtIndex("<", 0, true));
}
} }
} }

6
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/InsideAttributeValueTestFixture.cs

@ -104,5 +104,11 @@ namespace XmlEditor.Tests.Parser
string xml = "<foo a=\"''\""; string xml = "<foo a=\"''\"";
Assert.IsFalse(XmlParser.IsInsideAttributeValue(xml, xml.Length)); Assert.IsFalse(XmlParser.IsInsideAttributeValue(xml, xml.Length));
} }
[Test]
public void NullString()
{
Assert.IsFalse(XmlParser.IsInsideAttributeValue(null, 0));
}
} }
} }

6
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/NamespaceDeclarationTestFixture.cs

@ -116,5 +116,11 @@ namespace XmlEditor.Tests.Parser
bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length); bool isNamespace = XmlParser.IsNamespaceDeclaration(text, text.Length);
Assert.IsFalse(isNamespace, "Namespace should not be recognised."); Assert.IsFalse(isNamespace, "Namespace should not be recognised.");
} }
[Test]
public void NullString()
{
Assert.IsFalse(XmlParser.IsNamespaceDeclaration(null, 0));
}
} }
} }

Loading…
Cancel
Save