Browse Source

Fixed bugs in XmlParser when getting the attribute value and attribute name when the attribute value contains an equals sign.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4247 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
85e78d6762
  1. 21
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs
  2. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeValueUnderCursorTests.cs

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

@ -243,12 +243,15 @@ namespace ICSharpCode.XmlEditor
} }
// Find equals sign. // Find equals sign.
bool foundQuoteChar = false;
for (int i = index; i > elementStartIndex; --i) { for (int i = index; i > elementStartIndex; --i) {
char ch = xml[i]; char ch = xml[i];
if (ch == '=') { if (ch == '=' && foundQuoteChar) {
index = i; index = i;
ignoreEqualsSign = true; ignoreEqualsSign = true;
break; break;
} else if (IsQuoteChar(ch)) {
foundQuoteChar = true;
} }
} }
} else { } else {
@ -364,11 +367,14 @@ namespace ICSharpCode.XmlEditor
// Find equals sign. // Find equals sign.
int equalsSignIndex = -1; int equalsSignIndex = -1;
bool foundQuoteChar = false;
for (int i = index; i > elementStartIndex; --i) { for (int i = index; i > elementStartIndex; --i) {
char ch = xml[i]; char ch = xml[i];
if (ch == '=') { if (ch == '=' && foundQuoteChar) {
equalsSignIndex = i; equalsSignIndex = i;
break; break;
} else if (IsQuoteChar(ch)) {
foundQuoteChar = true;
} }
} }
@ -378,12 +384,12 @@ namespace ICSharpCode.XmlEditor
// Find attribute value. // Find attribute value.
char quoteChar = ' '; char quoteChar = ' ';
bool foundQuoteChar = false; foundQuoteChar = false;
StringBuilder attributeValue = new StringBuilder(); StringBuilder attributeValue = new StringBuilder();
for (int i = equalsSignIndex; i < xml.Length; ++i) { for (int i = equalsSignIndex; i < xml.Length; ++i) {
char ch = xml[i]; char ch = xml[i];
if (!foundQuoteChar) { if (!foundQuoteChar) {
if (ch == '\"' || ch == '\'') { if (IsQuoteChar(ch)) {
quoteChar = ch; quoteChar = ch;
foundQuoteChar = true; foundQuoteChar = true;
} }
@ -391,7 +397,7 @@ namespace ICSharpCode.XmlEditor
if (ch == quoteChar) { if (ch == quoteChar) {
// End of attribute value. // End of attribute value.
return attributeValue.ToString(); return attributeValue.ToString();
} else if (IsAttributeValueChar(ch) || (ch == '\"' || ch == '\'')) { } else if (IsAttributeValueChar(ch) || IsQuoteChar(ch)) {
attributeValue.Append(ch); attributeValue.Append(ch);
} else { } else {
// Invalid character found. // Invalid character found.
@ -783,5 +789,10 @@ namespace ICSharpCode.XmlEditor
} }
return new XmlElementPath(); return new XmlElementPath();
} }
static bool IsQuoteChar(char ch)
{
return (ch == '\"') || (ch == '\'');
}
} }
} }

2
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeValueUnderCursorTests.cs

@ -85,6 +85,8 @@ namespace XmlEditor.Tests.Parser
string xaml = "<Test val1=\"{Binding Value, Path=Control}\" />"; string xaml = "<Test val1=\"{Binding Value, Path=Control}\" />";
int offset = "<Test val1=\"{Binding Value, Path=".Length; int offset = "<Test val1=\"{Binding Value, Path=".Length;
Assert.IsTrue(XmlParser.IsInsideAttributeValue(xaml, offset)); Assert.IsTrue(XmlParser.IsInsideAttributeValue(xaml, offset));
Assert.AreEqual("{Binding Value, Path=Control}", XmlParser.GetAttributeValueAtIndex(xaml, offset));
Assert.AreEqual("val1", XmlParser.GetAttributeNameAtIndex(xaml, offset));
} }
[Test] [Test]

Loading…
Cancel
Save