From 997e9c3b4c60c313603a971129d849c9cee6df81 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Mon, 27 Apr 2020 23:02:28 +0200 Subject: [PATCH] XmlPropertyListParser: Support deserializing UID values --- plist-cil.test/UIDTests.cs | 5 ++--- plist-cil/XmlPropertyListParser.cs | 32 ++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/plist-cil.test/UIDTests.cs b/plist-cil.test/UIDTests.cs index 5371232..6eec0bc 100644 --- a/plist-cil.test/UIDTests.cs +++ b/plist-cil.test/UIDTests.cs @@ -88,9 +88,8 @@ namespace plistcil.test // UIDs don't exist in XML property lists, but they are represented as dictionaries // for compability purposes - var roundtrip = XmlPropertyListParser.ParseString(plist) as NSDictionary; - Assert.Single(roundtrip.Keys, "CF$UID"); - Assert.Single(roundtrip.Values, new NSNumber(0xabcd)); + var roundtrip = XmlPropertyListParser.ParseString(plist) as UID; + Assert.Equal(0xabcdUL, roundtrip.ToUInt64()); } } } \ No newline at end of file diff --git a/plist-cil/XmlPropertyListParser.cs b/plist-cil/XmlPropertyListParser.cs index f5ce9f5..60bc134 100644 --- a/plist-cil/XmlPropertyListParser.cs +++ b/plist-cil/XmlPropertyListParser.cs @@ -147,19 +147,31 @@ namespace Claunia.PropertyList { if(n.Name.Equals("dict")) { - NSDictionary dict = new NSDictionary(); - List children = FilterElementNodes(n.ChildNodes); - for(int i = 0; i < children.Count; i += 2) + // Special case for UID values + if(n.ChildNodes.Count == 2 + && n.ChildNodes[0].Name == "key" + && n.ChildNodes[0].InnerText == "CF$UID" + && n.ChildNodes[1].Name == "integer" + && uint.TryParse(n.ChildNodes[1].InnerText, out uint uidValue)) { - XmlNode key = children[i]; - XmlNode val = children[i + 1]; - - string keyString = GetNodeTextContents(key); - - dict.Add(keyString, ParseObject(val)); + return new UID(uidValue); } + else + { + NSDictionary dict = new NSDictionary(); + List children = FilterElementNodes(n.ChildNodes); + for(int i = 0; i < children.Count; i += 2) + { + XmlNode key = children[i]; + XmlNode val = children[i + 1]; - return dict; + string keyString = GetNodeTextContents(key); + + dict.Add(keyString, ParseObject(val)); + } + + return dict; + } } if(n.Name.Equals("array"))