Browse Source

Backslash characters now escaped when generating string property assignments in the python forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4230 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
a5746f751d
  1. 7
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs
  2. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonPropertyAssignmentToStringTests.cs

7
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs

@ -36,7 +36,7 @@ namespace ICSharpCode.PythonBinding @@ -36,7 +36,7 @@ namespace ICSharpCode.PythonBinding
{
Type propertyType = propertyValue.GetType();
if (propertyType == typeof(String)) {
return "\"" + propertyValue + "\"";
return GetQuotedString((string)propertyValue);
} else if (propertyType == typeof(Size)) {
Size size = (Size)propertyValue;
return size.GetType().FullName + "(" + size.Width + ", " + size.Height + ")";
@ -129,5 +129,10 @@ namespace ICSharpCode.PythonBinding @@ -129,5 +129,10 @@ namespace ICSharpCode.PythonBinding
}
return text.ToString();
}
static string GetQuotedString(string text)
{
return "\"" + text.Replace(@"\", @"\\") + "\"";
}
}
}

12
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonPropertyAssignmentToStringTests.cs

@ -79,5 +79,17 @@ namespace PythonBinding.Tests.Designer @@ -79,5 +79,17 @@ namespace PythonBinding.Tests.Designer
string expectedText = "System.Environment.SpecialFolder.ProgramFiles";
Assert.AreEqual(expectedText, PythonPropertyValueAssignment.ToString(folder));
}
/// <summary>
/// Ensures that when the user types in "\t" the code for a string property in the forms designer
/// the actual string is generated is "\\t".
/// </summary>
[Test]
public void BackslashCharactersEncodedInStrings()
{
string text = @"c:\temp";
string expectedText = "\"c:\\\\temp\"";
Assert.AreEqual(expectedText, PythonPropertyValueAssignment.ToString(text));
}
}
}

Loading…
Cancel
Save