if (itemSpec == null)
throw new ArgumentNullException ("itemSpec");
- this.itemSpec = itemSpec;
this.metadata = CollectionsUtil.CreateCaseInsensitiveHashtable ();
// FIXME: hack
public string GetMetadata (string metadataName)
{
if (ReservedNameUtils.IsReservedMetadataName (metadataName))
- return ReservedNameUtils.GetReservedMetadata (ItemSpec, metadataName, metadata);
+ return MSBuildUtils.Unescape (ReservedNameUtils.GetReservedMetadata (ItemSpec, metadataName, metadata));
else if (metadata.Contains (metadataName))
- return (string) metadata [metadataName];
+ return MSBuildUtils.Unescape ((string)metadata [metadataName]);
else
return String.Empty;
}
}
public string ItemSpec {
- get { return itemSpec; }
- set { itemSpec = value; }
+ get { return MSBuildUtils.Unescape (itemSpec); }
+ set { itemSpec = MSBuildUtils.Escape (value); }
}
public int MetadataCount {
using System;
using System.Collections;
using System.Collections.Specialized;
+using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NUnit.Framework;
new TaskItem ("itemspec", null);
}
+ [Test]
+ public void TestCtor_EscapedSpecialChar ()
+ {
+ // If we instantiate with the *escaped* metadata, it's unescaped automatically
+ var metadata = "foo@2x.png";
+ var escapedMetadata = global::Microsoft.Build.BuildEngine.Utilities.Escape ("foo@2x.png");
+ var item = new TaskItem (escapedMetadata);
+ item.SetMetadata ("mine", escapedMetadata);
+
+ Assert.AreEqual (metadata, item.ItemSpec, "#1");
+ Assert.AreEqual (metadata, item.GetMetadata ("Identity"), "#2");
+ Assert.AreEqual (Path.GetFileNameWithoutExtension (metadata), item.GetMetadata ("FileName"), "#3");
+ Assert.IsTrue (item.GetMetadata ("FullPath").EndsWith (metadata), "#4");
+ Assert.AreEqual (metadata, item.GetMetadata ("mine"), "#5");
+ }
+
+ [Test]
+ public void TestCtor_EscapedSpecialChar_BrokenEscaping ()
+ {
+ // This is badly escaped, but MSBuild does not care.
+ var metadata = "foo%4@2x.png";
+ var item = new TaskItem (metadata);
+
+ Assert.AreEqual (metadata, item.ItemSpec, "#1");
+ Assert.AreEqual (metadata, item.GetMetadata ("Identity"), "#2");
+ Assert.AreEqual (Path.GetFileNameWithoutExtension (metadata), item.GetMetadata ("FileName"), "#3");
+ Assert.IsTrue (item.GetMetadata ("FullPath").EndsWith (metadata), "#4");
+ }
+
+ [Test]
+ public void TestCtor_UnescapedSpecialChar ()
+ {
+ // If we instantiate with unescaped metadata, we get the same value back
+ var metadata = "foo@2x.png";
+ var item = new TaskItem (metadata);
+ item.SetMetadata ("mine", metadata);
+
+ Assert.AreEqual (metadata, item.ItemSpec, "#1");
+ Assert.AreEqual (metadata, item.GetMetadata ("Identity"), "#2");
+ Assert.AreEqual (Path.GetFileNameWithoutExtension (metadata), item.GetMetadata ("FileName"), "#3");
+ Assert.IsTrue (item.GetMetadata ("FullPath").EndsWith (metadata), "#4");
+ Assert.AreEqual (metadata, item.GetMetadata ("mine"), "#5");
+ }
+
[Test]
public void TestCopyConstructor ()
{