mirror of
https://github.com/claunia/plist-cil.git
synced 2025-12-16 19:14:26 +00:00
Merge pull request #8 from quamotion/fixes/xml-formatting
XML format compatibility with Apple
This commit is contained in:
@@ -138,6 +138,16 @@ namespace plistcil.test
|
|||||||
Assert.IsInstanceOf<double>(weight);
|
Assert.IsInstanceOf<double>(weight);
|
||||||
Assert.AreEqual(10d, (double)weight);
|
Assert.AreEqual(10d, (double)weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public static void RoundtripTest()
|
||||||
|
{
|
||||||
|
var expected = File.ReadAllText(@"test-files\Roundtrip.plist");
|
||||||
|
var value = XmlPropertyListParser.Parse(new FileInfo(@"test-files\Roundtrip.plist"));
|
||||||
|
var actual = value.ToXmlPropertyList();
|
||||||
|
|
||||||
|
Assert.AreEqual(expected, actual);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,9 @@
|
|||||||
<None Include="test-files\ResourceRules.plist">
|
<None Include="test-files\ResourceRules.plist">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="test-files\Roundtrip.plist">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\plist-cil\plist-cil.csproj">
|
<ProjectReference Include="..\plist-cil\plist-cil.csproj">
|
||||||
|
|||||||
80
plist-cil.test/test-files/Roundtrip.plist
Normal file
80
plist-cil.test/test-files/Roundtrip.plist
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>files</key>
|
||||||
|
<dict>
|
||||||
|
<key>PkgInfo</key>
|
||||||
|
<data>
|
||||||
|
n57qDP4tZfLD1rCS43W0B4LQjzE=
|
||||||
|
</data>
|
||||||
|
<key>icon.png</key>
|
||||||
|
<data>
|
||||||
|
EUOeOW/HpmiAZeEGzJm8j3hE6vo=
|
||||||
|
</data>
|
||||||
|
</dict>
|
||||||
|
<key>files2</key>
|
||||||
|
<dict>
|
||||||
|
<key>PkgInfo</key>
|
||||||
|
<data>
|
||||||
|
n57qDP4tZfLD1rCS43W0B4LQjzE=
|
||||||
|
</data>
|
||||||
|
<key>icon.png</key>
|
||||||
|
<data>
|
||||||
|
EUOeOW/HpmiAZeEGzJm8j3hE6vo=
|
||||||
|
</data>
|
||||||
|
</dict>
|
||||||
|
<key>rules</key>
|
||||||
|
<dict>
|
||||||
|
<key>.*</key>
|
||||||
|
<true/>
|
||||||
|
<key>Info.plist</key>
|
||||||
|
<dict>
|
||||||
|
<key>omit</key>
|
||||||
|
<true/>
|
||||||
|
<key>weight</key>
|
||||||
|
<real>10</real>
|
||||||
|
</dict>
|
||||||
|
<key>ResourceRules.plist</key>
|
||||||
|
<dict>
|
||||||
|
<key>omit</key>
|
||||||
|
<true/>
|
||||||
|
<key>weight</key>
|
||||||
|
<real>100</real>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>rules2</key>
|
||||||
|
<dict>
|
||||||
|
<key>.*</key>
|
||||||
|
<true/>
|
||||||
|
<key>Info.plist</key>
|
||||||
|
<dict>
|
||||||
|
<key>omit</key>
|
||||||
|
<true/>
|
||||||
|
<key>weight</key>
|
||||||
|
<real>10</real>
|
||||||
|
</dict>
|
||||||
|
<key>ResourceRules.plist</key>
|
||||||
|
<dict>
|
||||||
|
<key>omit</key>
|
||||||
|
<true/>
|
||||||
|
<key>weight</key>
|
||||||
|
<real>100</real>
|
||||||
|
</dict>
|
||||||
|
<key>^(Frameworks|SharedFrameworks|Plugins|Plug-ins|XPCServices|Helpers|MacOS)/</key>
|
||||||
|
<dict>
|
||||||
|
<key>nested</key>
|
||||||
|
<true/>
|
||||||
|
<key>weight</key>
|
||||||
|
<real>0.0</real>
|
||||||
|
</dict>
|
||||||
|
<key>^[^/]+$</key>
|
||||||
|
<dict>
|
||||||
|
<key>top</key>
|
||||||
|
<true/>
|
||||||
|
<key>weight</key>
|
||||||
|
<real>0.0</real>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@@ -156,7 +156,7 @@ namespace Claunia.PropertyList
|
|||||||
string base64 = GetBase64EncodedData();
|
string base64 = GetBase64EncodedData();
|
||||||
foreach (string line in base64.Split('\n'))
|
foreach (string line in base64.Split('\n'))
|
||||||
{
|
{
|
||||||
Indent(xml, level + 1);
|
Indent(xml, level);
|
||||||
xml.Append(line);
|
xml.Append(line);
|
||||||
xml.Append(NSObject.NEWLINE);
|
xml.Append(NSObject.NEWLINE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -354,7 +354,19 @@ namespace Claunia.PropertyList
|
|||||||
case REAL:
|
case REAL:
|
||||||
{
|
{
|
||||||
xml.Append("<real>");
|
xml.Append("<real>");
|
||||||
xml.Append(ToDouble().ToString(CultureInfo.InvariantCulture));
|
|
||||||
|
if (doubleValue == 0)
|
||||||
|
{
|
||||||
|
// 0 values appear to always roundtrip as 0.0,
|
||||||
|
// but non-zero values do not include decimals if
|
||||||
|
// not required (e.g. 10 -> "10")
|
||||||
|
xml.Append("0.0");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xml.Append(ToDouble().ToString(CultureInfo.InvariantCulture));
|
||||||
|
}
|
||||||
|
|
||||||
xml.Append("</real>");
|
xml.Append("</real>");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,10 +44,10 @@ namespace Claunia.PropertyList
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The newline character used for generating the XML output.
|
/// The newline character used for generating the XML output.
|
||||||
/// This constant will be different depending on the operating system on
|
/// To maintain compatibility with the Apple format, only a newline character
|
||||||
/// which you use this library.
|
/// is used (as opposed to cr+lf which is normally used on Windows).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
readonly internal static string NEWLINE = Environment.NewLine;
|
readonly internal static string NEWLINE = "\n";
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -100,6 +100,7 @@ namespace Claunia.PropertyList
|
|||||||
ToXml(xml, 0);
|
ToXml(xml, 0);
|
||||||
xml.Append(NSObject.NEWLINE);
|
xml.Append(NSObject.NEWLINE);
|
||||||
xml.Append("</plist>");
|
xml.Append("</plist>");
|
||||||
|
xml.Append(NSObject.NEWLINE);
|
||||||
return xml.ToString();
|
return xml.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user