Browse Source

Fixed SD2-1147. All parameters used in WiX xpath queries have any special XML characters encoded.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1864 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 19 years ago
parent
commit
f6f8fe0c62
  1. 21
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialog.cs
  2. 3
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs
  3. 3
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs
  4. 15
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs
  5. 9
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogTestFixture.cs
  6. 54
      src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextStyleNameWithSpecialXmlCharsTestFixture.cs
  7. 52
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxPropertyWithSpecialXmlCharsTestFixture.cs
  8. 53
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxPropertyWithSpecialXmlCharsTestFixture.cs
  9. 49
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewPropertyWithSpecialXmlCharsTestFixture.cs
  10. 53
      src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupPropertyWithSpecialXmlCharTestFixture.cs
  11. 50
      src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryWithSpecialXmlCharsTestFixture.cs
  12. 49
      src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/ShortFileNameExistsWithSpecialXmlCharsTestFixture.cs
  13. 6
      src/AddIns/BackendBindings/WixBinding/Test/Document/ExistingFileIdGenerationTests.cs
  14. 6
      src/AddIns/BackendBindings/WixBinding/Test/Document/GetBinaryFileNameTestFixture.cs
  15. 7
      src/AddIns/BackendBindings/WixBinding/Test/Document/GetDocumentPropertyTestFixture.cs
  16. 7
      src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj
  17. 95
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlEncoder.cs
  18. 1
      src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj
  19. 34
      src/AddIns/DisplayBindings/XmlEditor/Test/XPathQuery/EncodeXPathParameterTests.cs
  20. 1
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

21
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialog.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using ICSharpCode.Core;
using ICSharpCode.XmlEditor;
using System;
using System.ComponentModel;
using System.Collections;
@ -458,7 +459,7 @@ namespace ICSharpCode.WixBinding @@ -458,7 +459,7 @@ namespace ICSharpCode.WixBinding
/// </summary>
XmlNodeList GetRadioButtonElements(string property)
{
string xpath = String.Concat("//w:RadioButtonGroup[@Property='", property, "']/w:RadioButton");
string xpath = String.Concat("//w:RadioButtonGroup[@Property='", XmlEncode(property), "']/w:RadioButton");
return dialogElement.SelectNodes(xpath, namespaceManager);
}
@ -603,7 +604,7 @@ namespace ICSharpCode.WixBinding @@ -603,7 +604,7 @@ namespace ICSharpCode.WixBinding
/// </summary>
Font GetTextStyleFont(string name, Font defaultFont)
{
string xpath = String.Concat("//w:TextStyle[@Id='", name, "']");
string xpath = String.Concat("//w:TextStyle[@Id='", XmlEncode(name), "']");
XmlElement textStyleElement = (XmlElement)dialogElement.SelectSingleNode(xpath, namespaceManager);
if (textStyleElement != null) {
return CreateTextStyleFont(textStyleElement);
@ -825,7 +826,7 @@ namespace ICSharpCode.WixBinding @@ -825,7 +826,7 @@ namespace ICSharpCode.WixBinding
{
XmlElement controlElement = UpdateControlElement(parentLocation, control);
string property = controlElement.GetAttribute("Property");
string xpath = String.Concat("//w:RadioButtonGroup[@Property='", property, "']");
string xpath = String.Concat("//w:RadioButtonGroup[@Property='", XmlEncode(property), "']");
XmlElement radioButtonGroupElement = (XmlElement)controlElement.SelectSingleNode(xpath, namespaceManager);
if (radioButtonGroupElement == null) {
radioButtonGroupElement = AppendChildElement(controlElement, "RadioButtonGroup", control.PropertyName);
@ -991,7 +992,7 @@ namespace ICSharpCode.WixBinding @@ -991,7 +992,7 @@ namespace ICSharpCode.WixBinding
string elementName = controlElement.GetAttribute("Type");
// Add list items.
string xpath = String.Concat("//w:", elementName, "[@Property='", property, "']/w:ListItem");
string xpath = String.Concat("//w:", elementName, "[@Property='", XmlEncode(property), "']/w:ListItem");
foreach (XmlElement itemElement in dialogElement.SelectNodes(xpath, namespaceManager)) {
items.Add(GetControlText(itemElement));
}
@ -1004,7 +1005,7 @@ namespace ICSharpCode.WixBinding @@ -1004,7 +1005,7 @@ namespace ICSharpCode.WixBinding
{
XmlElement controlElement = UpdateControlElement(parentLocation, control);
string property = controlElement.GetAttribute("Property");
string xpath = String.Concat("//w:ListBox[@Property='", property, "']");
string xpath = String.Concat("//w:ListBox[@Property='", XmlEncode(property), "']");
XmlElement listBoxElement = (XmlElement)controlElement.SelectSingleNode(xpath, namespaceManager);
if (listBoxElement == null) {
listBoxElement = AppendChildElement(controlElement, "ListBox", property);
@ -1043,7 +1044,7 @@ namespace ICSharpCode.WixBinding @@ -1043,7 +1044,7 @@ namespace ICSharpCode.WixBinding
{
XmlElement controlElement = UpdateControlElement(parentLocation, control);
string property = controlElement.GetAttribute("Property");
string xpath = String.Concat("//w:ComboBox[@Property='", property, "']");
string xpath = String.Concat("//w:ComboBox[@Property='", XmlEncode(property), "']");
XmlElement comboBoxElement = (XmlElement)controlElement.SelectSingleNode(xpath, namespaceManager);
if (comboBoxElement == null) {
comboBoxElement = AppendChildElement(controlElement, "ComboBox", property);
@ -1082,7 +1083,7 @@ namespace ICSharpCode.WixBinding @@ -1082,7 +1083,7 @@ namespace ICSharpCode.WixBinding
{
XmlElement controlElement = UpdateControlElement(parentLocation, control);
string property = controlElement.GetAttribute("Property");
string xpath = String.Concat("//w:ListView[@Property='", property, "']");
string xpath = String.Concat("//w:ListView[@Property='", XmlEncode(property), "']");
XmlElement listViewElement = (XmlElement)controlElement.SelectSingleNode(xpath, namespaceManager);
if (listViewElement == null) {
listViewElement = AppendChildElement(controlElement, "ListView", property);
@ -1143,5 +1144,11 @@ namespace ICSharpCode.WixBinding @@ -1143,5 +1144,11 @@ namespace ICSharpCode.WixBinding
}
return document.GetBitmapFromId(id);
}
static string XmlEncode(string item)
{
char quoteChar = '\'';
return XmlEncoder.Encode(item, quoteChar);
}
}
}

3
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using ICSharpCode.Core;
using ICSharpCode.XmlEditor;
using System;
using System.Collections.Generic;
using System.IO;
@ -125,7 +126,7 @@ namespace ICSharpCode.WixBinding @@ -125,7 +126,7 @@ namespace ICSharpCode.WixBinding
/// </summary>
public bool ShortFileNameExists(string fileName)
{
string xpath = String.Concat("w:Component/w:File[@Name='", fileName, "']");
string xpath = String.Concat("w:Component/w:File[@Name='", XmlEncoder.Encode(fileName, '\''), "']");
XmlNodeList nodes = SelectNodes(xpath, new WixNamespaceManager(OwnerDocument.NameTable));
return nodes.Count > 0;
}

3
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.XmlEditor;
using System;
using System.Collections.Generic;
using System.Xml;
@ -97,7 +98,7 @@ namespace ICSharpCode.WixBinding @@ -97,7 +98,7 @@ namespace ICSharpCode.WixBinding
/// </summary>
bool ShortNameExists(string name)
{
string xpath = String.Concat("w:Directory[@Name='", name, "']");
string xpath = String.Concat("w:Directory[@Name='", XmlEncoder.Encode(name, '\''), "']");
XmlNodeList nodes = SelectNodes(xpath, new WixNamespaceManager(OwnerDocument.NameTable));
return nodes.Count > 0;
}

15
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs

@ -10,6 +10,7 @@ using ICSharpCode.NRefactory; @@ -10,6 +10,7 @@ using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.XmlEditor;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -475,7 +476,7 @@ namespace ICSharpCode.WixBinding @@ -475,7 +476,7 @@ namespace ICSharpCode.WixBinding
/// <returns><see langword="null"/> if the id cannot be found.</returns>
public string GetBinaryFileName(string id)
{
string xpath = String.Concat("//w:Binary[@Id='", id, "']");
string xpath = String.Concat("//w:Binary[@Id='", XmlEncode(id), "']");
WixBinaryElement binaryElement = (WixBinaryElement)SelectSingleNode(xpath, namespaceManager);
if (binaryElement != null) {
return binaryElement.FileName;
@ -509,7 +510,7 @@ namespace ICSharpCode.WixBinding @@ -509,7 +510,7 @@ namespace ICSharpCode.WixBinding
/// <returns>The property value if it is found; an empty string otherwise.</returns>
public string GetProperty(string name)
{
string xpath = String.Concat("//w:Property[@Id='", name, "']");
string xpath = String.Concat("//w:Property[@Id='", XmlEncode(name), "']");
XmlElement textStyleElement = (XmlElement)SelectSingleNode(xpath, namespaceManager);
if (textStyleElement != null) {
return textStyleElement.InnerText;
@ -811,7 +812,7 @@ namespace ICSharpCode.WixBinding @@ -811,7 +812,7 @@ namespace ICSharpCode.WixBinding
/// </summary>
XmlElement GetDialogElement(string id)
{
string xpath = String.Concat("//w:Dialog[@Id='", id, "']");
string xpath = String.Concat("//w:Dialog[@Id='", XmlEncode(id), "']");
return (XmlElement)SelectSingleNode(xpath, namespaceManager);
}
@ -820,9 +821,15 @@ namespace ICSharpCode.WixBinding @@ -820,9 +821,15 @@ namespace ICSharpCode.WixBinding
/// </summary>
bool ElementIdExists(string elementName, string id)
{
string xpath = String.Concat("//w:", elementName, "[@Id='", id, "']");
string xpath = String.Concat("//w:", elementName, "[@Id='", XmlEncode(id), "']");
XmlNodeList nodes = SelectNodes(xpath, new WixNamespaceManager(NameTable));
return nodes.Count > 0;
}
static string XmlEncode(string item)
{
char quoteChar = '\'';
return XmlEncoder.Encode(item, quoteChar);
}
}
}

9
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogTestFixture.cs

@ -27,11 +27,12 @@ namespace WixBinding.Tests.DialogLoading @@ -27,11 +27,12 @@ namespace WixBinding.Tests.DialogLoading
Size clientSize;
bool maximizeBox;
bool minimizeBox;
WixDocument doc;
[TestFixtureSetUp]
public void SetUpFixture()
{
WixDocument doc = new WixDocument();
doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
using (Form simpleDialog = wixDialog.CreateDialog()) {
@ -80,6 +81,12 @@ namespace WixBinding.Tests.DialogLoading @@ -80,6 +81,12 @@ namespace WixBinding.Tests.DialogLoading
{
Assert.IsFalse(maximizeBox);
}
[Test]
public void DialogIdWithSingleQuote()
{
Assert.IsNull(doc.GetDialog("Test'Id"));
}
string GetWixXml()
{

54
src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextStyleNameWithSpecialXmlCharsTestFixture.cs

@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
// <file>
// <copyright see='prj:///doc/copyright.txt'/>
// <license see='prj:///doc/license.txt'/>
// <owner name='Matthew Ward' email='mrward@users.sourceforge.net'/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogLoading
{
[TestFixture]
public class TextStyleNameWithSpecialXmlCharsTestFixture : DialogLoadingTestFixtureBase
{
[Test]
public void CreateDialog()
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
using (Form dialog = wixDialog.CreateDialog(this)) {
}
}
string GetWixXml()
{
return "<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>\r\n" +
"\t<Fragment>\r\n" +
"\t\t<UI>\r\n" +
"\t\t\t<Property Id='BigFont'>{&amp;BigFont'Style}</Property>\r\n" +
"\t\t\t<TextStyle Id=\"BigFont'Style\" FaceName='Verdana' Size='13' Bold='yes' />\r\n" +
"\t\t\t<Property Id='SmallFont'>{\\SmallFontStyle}</Property>\r\n" +
"\t\t\t<TextStyle Id='SmallFontStyle' FaceName='Arial' Size='10'/>\r\n" +
"\t\t\t<Dialog Id='WelcomeDialog' Height='270' Width='370'>\r\n" +
"\t\t\t\t<Control Id='Title' Type='Text' X='135' Y='20' Width='220' Height='60' Transparent='yes' NoPrefix='yes'>\r\n" +
"\t\t\t\t\t<Text>[BigFont]Welcome to the [ProductName] installation</Text>\r\n" +
"\t\t\t\t</Control>\r\n" +
"\t\t\t\t<Control Id='Description' Type='Text' X='135' Y='20' Width='220' Height='60' Transparent='yes' NoPrefix='yes'>\r\n" +
"\t\t\t\t\t<Text>[SmallFont]Install text...</Text>\r\n" +
"\t\t\t\t</Control>\r\n" +
"\t\t\t</Dialog>\r\n" +
"\t\t</UI>\r\n" +
"\t</Fragment>\r\n" +
"</Wix>";
}
}
}

52
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxPropertyWithSpecialXmlCharsTestFixture.cs

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogXmlGeneration
{
[TestFixture]
public class ComboBoxPropertyWithSpecialXmlCharsTestFixture : DialogLoadingTestFixtureBase
{
[Test]
public void UpdateDialogElement()
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
using (Form dialog = wixDialog.CreateDialog(this)) {
XmlElement dialogElement = wixDialog.UpdateDialogElement(dialog);
}
}
string GetWixXml()
{
return "<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>\r\n" +
"\t<Fragment>\r\n" +
"\t\t<UI>\r\n" +
"\t\t\t<Dialog Id='WelcomeDialog' Height='270' Width='370'>\r\n" +
"\t\t\t\t<Control Id='ComboBox1' Type='ComboBox' X='20' Y='187' Width='330' Height='40' Property=\"ComboBox'Property\"/>\r\n" +
"\t\t\t</Dialog>\r\n" +
"\t\t\t<ComboBox Property=\"ComboBox'Property\">\r\n" +
"\t\t\t</ComboBox>\r\n" +
"\t\t</UI>\r\n" +
"\t</Fragment>\r\n" +
"</Wix>";
}
}
}

53
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxPropertyWithSpecialXmlCharsTestFixture.cs

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogXmlGeneration
{
[TestFixture]
public class ListBoxPropertyWithSpecialXmlCharsTestFixture : DialogLoadingTestFixtureBase
{
[Test]
public void UpdateDialogElement()
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
using (Form dialog = wixDialog.CreateDialog(this)) {
XmlElement dialogElement = wixDialog.UpdateDialogElement(dialog);
}
}
string GetWixXml()
{
return "<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>\r\n" +
"\t<Fragment>\r\n" +
"\t\t<UI>\r\n" +
"\t\t\t<Dialog Id='WelcomeDialog' Height='270' Width='370'>\r\n" +
"\t\t\t\t<Control Id='ListBox1' Type='ListBox' X='20' Y='187' Width='330' Height='40' Property=\"ListBox'Property\"/>\r\n" +
"\t\t\t</Dialog>\r\n" +
"\t\t\t<ListBox Property=\"ListBox'Property\">\r\n" +
"\t\t\t\t<ListItem Text='first'/>\r\n" +
"\t\t\t\t<ListItem Text='second'/>\r\n" +
"\t\t\t</ListBox>\r\n" +
"\t\t</UI>\r\n" +
"\t</Fragment>\r\n" +
"</Wix>";
}
}
}

49
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewPropertyWithSpecialXmlCharsTestFixture.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogXmlGeneration
{
[TestFixture]
public class ListViewPropertyWithSpecialXmlCharsTestFixture : DialogLoadingTestFixtureBase
{
[Test]
public void UpdateDialogElement()
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("WelcomeDialog");
using (Form dialog = wixDialog.CreateDialog(this)) {
XmlElement dialogElement = wixDialog.UpdateDialogElement(dialog);
}
}
string GetWixXml()
{
return "<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>\r\n" +
"\t<Fragment>\r\n" +
"\t\t<UI>\r\n" +
"\t\t\t<Dialog Id='WelcomeDialog' Height='270' Width='370'>\r\n" +
"\t\t\t\t<Control Id='ListView1' Type='ListView' X='20' Y='187' Width='330' Height='40' Property=\"ListView'Property\"/>\r\n" +
"\t\t\t</Dialog>\r\n" +
"\t\t\t<ListView Property=\"ListView'Property\">\r\n" +
"\t\t\t</ListView>\r\n" +
"\t\t</UI>\r\n" +
"\t</Fragment>\r\n" +
"</Wix>";
}
}
}

53
src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupPropertyWithSpecialXmlCharTestFixture.cs

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using WixBinding;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DialogXmlGeneration
{
[TestFixture]
public class RadioButtonGroupPropertyWithSpecialXmlCharTestFixture : DialogLoadingTestFixtureBase
{
[Test]
public void UpdateDialogElement()
{
WixDocument doc = new WixDocument();
doc.LoadXml(GetWixXml());
CreatedComponents.Clear();
WixDialog wixDialog = doc.GetDialog("AcceptLicenseDialog");
using (Form dialog = wixDialog.CreateDialog(this)) {
XmlElement dialogElement = wixDialog.UpdateDialogElement(dialog);
}
}
string GetWixXml()
{
return "<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>\r\n" +
"\t<Fragment>\r\n" +
"\t\t<UI>\r\n" +
"\t\t\t<Dialog Id='AcceptLicenseDialog' Height='270' Width='370'>\r\n" +
"\t\t\t\t<Control Id='Buttons' Type='RadioButtonGroup' X='20' Y='187' Width='330' Height='40' Property=\"Accept'License\"/>\r\n" +
"\t\t\t</Dialog>\r\n" +
"\t\t\t<RadioButtonGroup Property=\"Accept'License\">\r\n" +
"\t\t\t\t<RadioButton Text='I accept' X='5' Y='0' Width='300' Height='15' Value='Yes'/>\r\n" +
"\t\t\t\t<RadioButton Text='I do not accept' X='5' Y='20' Width='300' Height='15' Value='No'/>\r\n" +
"\t\t\t</RadioButtonGroup>\r\n" +
"\t\t</UI>\r\n" +
"\t</Fragment>\r\n" +
"</Wix>";
}
}
}

50
src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryWithSpecialXmlCharsTestFixture.cs

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
namespace WixBinding.Tests.DirectoryImport
{
[TestFixture]
public class AddDirectoryWithSpecialXmlCharsTestFixture
{
WixDocument document;
[SetUp]
public void Init()
{
document = new WixDocument();
document.FileName = @"C:\Projects\Test\Setup.wxs";
document.LoadXml(GetWixXml());
}
[Test]
public void AddDirectoryWithSingleQuoteChar()
{
string directoryName = "Test'directory";
WixDirectoryElement element = document.RootDirectory.AddDirectory(directoryName);
Assert.AreEqual(directoryName, element.DirectoryName);
}
string GetWixXml()
{
return "<Wix xmlns=\"http://schemas.microsoft.com/wix/2003/01/wi\">\r\n" +
"\t<Product Name=\"MySetup\" \r\n" +
"\t Manufacturer=\"\" \r\n" +
"\t Id=\"F4A71A3A-C271-4BE8-B72C-F47CC956B3AA\" \r\n" +
"\t Language=\"1033\" \r\n" +
"\t Version=\"1.0.0.0\">\r\n" +
"\t\t<Package Id=\"6B8BE64F-3768-49CA-8BC2-86A76424DFE9\"/>\r\n" +
"\t\t<Directory Id=\"TARGETDIR\" SourceName=\"SourceDir\">\r\n" +
"\t\t</Directory>\r\n" +
"\t</Product>\r\n" +
"</Wix>";
}
}
}

49
src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/ShortFileNameExistsWithSpecialXmlCharsTestFixture.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
namespace WixBinding.Tests.DirectoryImport
{
[TestFixture]
public class ShortFileNameExistsWithSpecialXmlCharsTestFixture
{
WixDocument document;
[SetUp]
public void Init()
{
document = new WixDocument();
document.FileName = @"C:\Projects\Test\Setup.wxs";
document.LoadXml(GetWixXml());
}
[Test]
public void FileNameWithSingleQuote()
{
string fileName = "Test'file";
Assert.IsFalse(document.RootDirectory.ShortFileNameExists(fileName));
}
string GetWixXml()
{
return "<Wix xmlns=\"http://schemas.microsoft.com/wix/2003/01/wi\">\r\n" +
"\t<Product Name=\"MySetup\" \r\n" +
"\t Manufacturer=\"\" \r\n" +
"\t Id=\"F4A71A3A-C271-4BE8-B72C-F47CC956B3AA\" \r\n" +
"\t Language=\"1033\" \r\n" +
"\t Version=\"1.0.0.0\">\r\n" +
"\t\t<Package Id=\"6B8BE64F-3768-49CA-8BC2-86A76424DFE9\"/>\r\n" +
"\t\t<Directory Id=\"TARGETDIR\" SourceName=\"SourceDir\">\r\n" +
"\t\t</Directory>\r\n" +
"\t</Product>\r\n" +
"</Wix>";
}
}
}

6
src/AddIns/BackendBindings/WixBinding/Test/Document/ExistingFileIdGenerationTests.cs

@ -78,6 +78,12 @@ namespace WixBinding.Tests.Document @@ -78,6 +78,12 @@ namespace WixBinding.Tests.Document
Assert.AreEqual("doc.license1.txt", fileElement.Id);
}
[Test]
public void FileIdWithSingleQuote()
{
Assert.IsFalse(doc.FileIdExists("lice'nse.txt"));
}
string GetWixXml()
{
return "<Wix xmlns=\"http://schemas.microsoft.com/wix/2003/01/wi\">\r\n" +

6
src/AddIns/BackendBindings/WixBinding/Test/Document/GetBinaryFileNameTestFixture.cs

@ -47,6 +47,12 @@ namespace WixBinding.Tests.Document @@ -47,6 +47,12 @@ namespace WixBinding.Tests.Document
Assert.AreEqual("Bitmaps/Info.ico", document.GetBinaryFileName("Info"));
}
[Test]
public void SingleQuoteInBinaryFileName()
{
Assert.AreEqual(null, document.GetBinaryFileName("test'id"));
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void PassingFileLoaderIntoWixDocument()

7
src/AddIns/BackendBindings/WixBinding/Test/Document/GetDocumentPropertyTestFixture.cs

@ -39,6 +39,13 @@ namespace WixBinding.Tests.Document @@ -39,6 +39,13 @@ namespace WixBinding.Tests.Document
{
Assert.AreEqual(String.Empty, doc.GetProperty("MissingProperty"));
}
[Test]
public void PropertyWithSingleQuoteInName()
{
Assert.AreEqual(String.Empty, doc.GetProperty("Test'Property"));
}
string GetWixXml()
{
return "<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>\r\n" +

7
src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj

@ -211,6 +211,13 @@ @@ -211,6 +211,13 @@
<Compile Include="PackageFiles\GetRelativeFileNameTestFixture.cs" />
<Compile Include="PropertyGrid\DropDownTypeEditorTestFixture.cs" />
<Compile Include="PropertyGrid\DropDownPropertyDescriptorTestFixture.cs" />
<Compile Include="DirectoryImport\AddDirectoryWithSpecialXmlCharsTestFixture.cs" />
<Compile Include="DirectoryImport\ShortFileNameExistsWithSpecialXmlCharsTestFixture.cs" />
<Compile Include="DialogXmlGeneration\RadioButtonGroupPropertyWithSpecialXmlCharTestFixture.cs" />
<Compile Include="DialogXmlGeneration\ListBoxPropertyWithSpecialXmlCharsTestFixture.cs" />
<Compile Include="DialogXmlGeneration\ComboBoxPropertyWithSpecialXmlCharsTestFixture.cs" />
<Compile Include="DialogXmlGeneration\ListViewPropertyWithSpecialXmlCharsTestFixture.cs" />
<Compile Include="DialogLoading\TextStyleNameWithSpecialXmlCharsTestFixture.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Project\WixBinding.csproj">

95
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlEncoder.cs

@ -0,0 +1,95 @@ @@ -0,0 +1,95 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using System.Text;
using System.Xml;
namespace ICSharpCode.XmlEditor
{
/// <summary>
/// Utility class that will encode special XML characters.
/// </summary>
public sealed class XmlEncoder
{
XmlEncoder()
{
}
/// <summary>
/// Encodes any special characters in the xml string.
/// </summary>
public static string Encode(string xml, char quoteCharacter)
{
XmlEncoderTextWriter encoderWriter = new XmlEncoderTextWriter();
using (XmlTextWriter writer = new XmlTextWriter(encoderWriter)) {
writer.WriteStartElement("root");
writer.WriteStartAttribute("attribute");
writer.QuoteChar = quoteCharacter;
encoderWriter.BeginMarkup();
writer.WriteString(xml);
return encoderWriter.Markup;
}
}
/// <summary>
/// Special XmlTextWriter that will return the last item written to
/// it from a certain point. This is used by the XmlEncoder to
/// get the encoded attribute string so the XmlEncoder does not
/// have to do the special character encoding itself, but can
/// use the .NET framework to do the work.
/// </summary>
class XmlEncoderTextWriter : EncodedStringWriter
{
StringBuilder markup = new StringBuilder();
bool saveMarkupText;
public XmlEncoderTextWriter() : base(Encoding.UTF8)
{
}
/// <summary>
/// Sets the point from which we are interested in
/// saving the string written to the text writer.
/// </summary>
public void BeginMarkup()
{
saveMarkupText = true;
markup = new StringBuilder();
}
public void EndMarkup()
{
saveMarkupText = false;
}
/// <summary>
/// Returns the string written to this text writer after the
/// BeginMarkup method was called.
/// </summary>
public string Markup {
get {
return markup.ToString();
}
}
public override void Write(string text)
{
base.Write(text);
markup.Append(text);
}
public override void Write(char value)
{
base.Write(value);
markup.Append(value);
}
}
}
}

1
src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj

@ -126,6 +126,7 @@ @@ -126,6 +126,7 @@
<EmbeddedResource Include="Resources\XmlTextTreeNodeIcon.png" />
<Compile Include="Src\XmlAttributePropertyDescriptor.cs" />
<Compile Include="Src\XmlAttributeTypeDescriptor.cs" />
<Compile Include="Src\XmlEncoder.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">

34
src/AddIns/DisplayBindings/XmlEditor/Test/XPathQuery/EncodeXPathParameterTests.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.XmlEditor;
using NUnit.Framework;
using System;
namespace XmlEditor.Tests.XPathQuery
{
/// <summary>
/// Tests the XmlEncoder class's Encode method which
/// makes sure that a parameter being used in an xpath string is
/// correctly encoded.
/// </summary>
[TestFixture]
public class EncodeXPathParameterTests
{
[Test]
public void SingleQuote()
{
Assert.AreEqual("&apos;", XmlEncoder.Encode("'", '\''));
}
[Test]
public void Ampersand()
{
Assert.AreEqual("&amp;", XmlEncoder.Encode("&", '\''));
}
}
}

1
src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

@ -134,6 +134,7 @@ @@ -134,6 +134,7 @@
<Compile Include="Tree\TreeControlViewStateTestFixture.cs" />
<Compile Include="Tree\AttributeChangedTestFixture.cs" />
<Compile Include="Tree\TextNodeTextChangedTestFixture.cs" />
<Compile Include="XPathQuery\EncodeXPathParameterTests.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Schema\" />

Loading…
Cancel
Save