Browse Source

Merge pull request #478 from gumme/WpfDesignerMarkupExtensionParserFix

Wpf designer markup extension parser fix
pull/480/head
Siegfried Pammer 11 years ago
parent
commit
410813bfb2
  1. 51
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/MarkupExtensionTests.cs
  2. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionParser.cs

51
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/MarkupExtensionTests.cs

@ -27,6 +27,10 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -27,6 +27,10 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
[TestFixture]
public class MarkupExtensionTests : TestHelper
{
private const string PathWithSpaces = @"C:\\Folder A\\SubFolder A\\SubFolder B\\file with spaces.txt";
private const string PathWithoutSpaces = @"C:\\FolderA\\SubFolderA\\SubFolderB\\file.txt";
private const string PathWithCommasAndSpaces = @"C:\\Folder A\\Sub,Folder,A\\SubFolderB\\file,with,commas and spaces.txt";
[Test]
public void Test1()
{
@ -84,6 +88,36 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -84,6 +88,36 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
{
TestMarkupExtension("Content=\"{x:Static t:MyStaticClass.StaticString}\"");
}
[Test]
public void TestPathWithSpaces()
{
TestMarkupExtension("Content=\"{t:String " + PathWithSpaces + "}\"");
}
[Test]
public void TestQuotedPathWithSpaces()
{
TestMarkupExtension("Content=\"{t:String '" + PathWithSpaces + "'}\"");
}
[Test]
public void TestPathWithoutSpaces()
{
TestMarkupExtension("Content=\"{t:String " + PathWithoutSpaces + "}\"");
}
[Test]
public void TestQuotedPathWithoutSpaces()
{
TestMarkupExtension("Content=\"{t:String '" + PathWithoutSpaces + "'}\"");
}
[Test]
public void TestQuotedPathWithCommasAndSpaces()
{
TestMarkupExtension("Content=\"{t:String '" + PathWithCommasAndSpaces + "'}\"");
}
// [Test]
// public void Test10()
@ -114,6 +148,23 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -114,6 +148,23 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
{
public static string StaticString = "a";
}
public class StringExtension : MarkupExtension
{
readonly string s;
public StringExtension(string s)
{
TestHelperLog.Log(this.GetType().Name + " " + s);
this.s = s;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return s;
}
}
public class MyExtension : MarkupExtension
{

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionParser.cs

@ -96,10 +96,17 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -96,10 +96,17 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (text[pos] == '"' || text[pos] == '\'') {
char quote = text[pos++];
CheckNotEOF();
int lastBackslashPos = -1;
while (!(text[pos] == quote && text[pos-1] != '\\')) {
int current = pos;
char c = text[pos++];
if (c != '\\')
//check if string is \\ and that the last backslash is not the previously saved char, ie that \\\\ does not become \\\ but just \\
bool isEscapedBackslash = string.Concat(text[current-1],c)=="\\\\" && current-1 != lastBackslashPos;
if (c != '\\' || isEscapedBackslash){
b.Append(c);
if(isEscapedBackslash)
lastBackslashPos = current;
}
CheckNotEOF();
}
pos++; // consume closing quote

Loading…
Cancel
Save