Merge pull request #8 from quamotion/fixes/xml-formatting

XML format compatibility with Apple
This commit is contained in:
2016-06-24 22:04:12 +01:00
committed by GitHub
6 changed files with 111 additions and 5 deletions

View File

@@ -138,6 +138,16 @@ namespace plistcil.test
Assert.IsInstanceOf<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);
}
}
}

View File

@@ -119,6 +119,9 @@
<None Include="test-files\ResourceRules.plist">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="test-files\Roundtrip.plist">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\plist-cil\plist-cil.csproj">

View 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>

View File

@@ -156,7 +156,7 @@ namespace Claunia.PropertyList
string base64 = GetBase64EncodedData();
foreach (string line in base64.Split('\n'))
{
Indent(xml, level + 1);
Indent(xml, level);
xml.Append(line);
xml.Append(NSObject.NEWLINE);
}

View File

@@ -354,7 +354,19 @@ namespace Claunia.PropertyList
case 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>");
break;
}

View File

@@ -44,10 +44,10 @@ namespace Claunia.PropertyList
{
/// <summary>
/// The newline character used for generating the XML output.
/// This constant will be different depending on the operating system on
/// which you use this library.
/// To maintain compatibility with the Apple format, only a newline character
/// is used (as opposed to cr+lf which is normally used on Windows).
/// </summary>
readonly internal static string NEWLINE = Environment.NewLine;
readonly internal static string NEWLINE = "\n";
/// <summary>
@@ -100,6 +100,7 @@ namespace Claunia.PropertyList
ToXml(xml, 0);
xml.Append(NSObject.NEWLINE);
xml.Append("</plist>");
xml.Append(NSObject.NEWLINE);
return xml.ToString();
}