From 85e78d67629290063c4831ec43ffc6b4ee99a7fa Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sat, 6 Jun 2009 11:32:00 +0000 Subject: [PATCH] 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 --- .../XmlEditor/Project/Src/XmlParser.cs | 21 ++++++++++++++----- .../Parser/AttributeValueUnderCursorTests.cs | 2 ++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs index 407ae7feef..19d70bd547 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs @@ -243,12 +243,15 @@ namespace ICSharpCode.XmlEditor } // Find equals sign. + bool foundQuoteChar = false; for (int i = index; i > elementStartIndex; --i) { char ch = xml[i]; - if (ch == '=') { + if (ch == '=' && foundQuoteChar) { index = i; ignoreEqualsSign = true; break; + } else if (IsQuoteChar(ch)) { + foundQuoteChar = true; } } } else { @@ -364,11 +367,14 @@ namespace ICSharpCode.XmlEditor // Find equals sign. int equalsSignIndex = -1; + bool foundQuoteChar = false; for (int i = index; i > elementStartIndex; --i) { char ch = xml[i]; - if (ch == '=') { + if (ch == '=' && foundQuoteChar) { equalsSignIndex = i; break; + } else if (IsQuoteChar(ch)) { + foundQuoteChar = true; } } @@ -378,12 +384,12 @@ namespace ICSharpCode.XmlEditor // Find attribute value. char quoteChar = ' '; - bool foundQuoteChar = false; + foundQuoteChar = false; StringBuilder attributeValue = new StringBuilder(); for (int i = equalsSignIndex; i < xml.Length; ++i) { char ch = xml[i]; if (!foundQuoteChar) { - if (ch == '\"' || ch == '\'') { + if (IsQuoteChar(ch)) { quoteChar = ch; foundQuoteChar = true; } @@ -391,7 +397,7 @@ namespace ICSharpCode.XmlEditor if (ch == quoteChar) { // End of attribute value. return attributeValue.ToString(); - } else if (IsAttributeValueChar(ch) || (ch == '\"' || ch == '\'')) { + } else if (IsAttributeValueChar(ch) || IsQuoteChar(ch)) { attributeValue.Append(ch); } else { // Invalid character found. @@ -783,5 +789,10 @@ namespace ICSharpCode.XmlEditor } return new XmlElementPath(); } + + static bool IsQuoteChar(char ch) + { + return (ch == '\"') || (ch == '\''); + } } } \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeValueUnderCursorTests.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeValueUnderCursorTests.cs index bbbddb9ac9..828618e238 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeValueUnderCursorTests.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeValueUnderCursorTests.cs @@ -85,6 +85,8 @@ namespace XmlEditor.Tests.Parser string xaml = ""; int offset = "