Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 410813b

Browse files
Merge pull request #478 from gumme/WpfDesignerMarkupExtensionParserFix
Wpf designer markup extension parser fix
2 parents 7c5b1f9 + 6697216 commit 410813b

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
2727
[TestFixture]
2828
public class MarkupExtensionTests : TestHelper
2929
{
30+
private const string PathWithSpaces = @"C:\\Folder A\\SubFolder A\\SubFolder B\\file with spaces.txt";
31+
private const string PathWithoutSpaces = @"C:\\FolderA\\SubFolderA\\SubFolderB\\file.txt";
32+
private const string PathWithCommasAndSpaces = @"C:\\Folder A\\Sub,Folder,A\\SubFolderB\\file,with,commas and spaces.txt";
33+
3034
[Test]
3135
public void Test1()
3236
{
@@ -84,6 +88,36 @@ public void Test9()
8488
{
8589
TestMarkupExtension("Content=\"{x:Static t:MyStaticClass.StaticString}\"");
8690
}
91+
92+
[Test]
93+
public void TestPathWithSpaces()
94+
{
95+
TestMarkupExtension("Content=\"{t:String " + PathWithSpaces + "}\"");
96+
}
97+
98+
[Test]
99+
public void TestQuotedPathWithSpaces()
100+
{
101+
TestMarkupExtension("Content=\"{t:String '" + PathWithSpaces + "'}\"");
102+
}
103+
104+
[Test]
105+
public void TestPathWithoutSpaces()
106+
{
107+
TestMarkupExtension("Content=\"{t:String " + PathWithoutSpaces + "}\"");
108+
}
109+
110+
[Test]
111+
public void TestQuotedPathWithoutSpaces()
112+
{
113+
TestMarkupExtension("Content=\"{t:String '" + PathWithoutSpaces + "'}\"");
114+
}
115+
116+
[Test]
117+
public void TestQuotedPathWithCommasAndSpaces()
118+
{
119+
TestMarkupExtension("Content=\"{t:String '" + PathWithCommasAndSpaces + "'}\"");
120+
}
87121

88122
// [Test]
89123
// public void Test10()
@@ -114,6 +148,23 @@ public static class MyStaticClass
114148
{
115149
public static string StaticString = "a";
116150
}
151+
152+
public class StringExtension : MarkupExtension
153+
{
154+
readonly string s;
155+
156+
public StringExtension(string s)
157+
{
158+
TestHelperLog.Log(this.GetType().Name + " " + s);
159+
160+
this.s = s;
161+
}
162+
163+
public override object ProvideValue(IServiceProvider serviceProvider)
164+
{
165+
return s;
166+
}
167+
}
117168

118169
public class MyExtension : MarkupExtension
119170
{

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,17 @@ void MembernameOrString()
9696
if (text[pos] == '"' || text[pos] == '\'') {
9797
char quote = text[pos++];
9898
CheckNotEOF();
99+
int lastBackslashPos = -1;
99100
while (!(text[pos] == quote && text[pos-1] != '\\')) {
101+
int current = pos;
100102
char c = text[pos++];
101-
if (c != '\\')
103+
//check if string is \\ and that the last backslash is not the previously saved char, ie that \\\\ does not become \\\ but just \\
104+
bool isEscapedBackslash = string.Concat(text[current-1],c)=="\\\\" && current-1 != lastBackslashPos;
105+
if (c != '\\' || isEscapedBackslash){
102106
b.Append(c);
107+
if(isEscapedBackslash)
108+
lastBackslashPos = current;
109+
}
103110
CheckNotEOF();
104111
}
105112
pos++; // consume closing quote

0 commit comments

Comments
 (0)