diff --git a/plist-cil.test/ParseTest.cs b/plist-cil.test/ParseTest.cs index 0388d15..e8a7eb8 100644 --- a/plist-cil.test/ParseTest.cs +++ b/plist-cil.test/ParseTest.cs @@ -283,6 +283,16 @@ namespace plistcil.test return false; } - } + [Fact] + public static void testAsciiUtf8CharactersInQuotedString() + { + NSObject x = PropertyListParser.Parse(new FileInfo("test-files/test-ascii-utf8.plist")); + NSDictionary d = (NSDictionary)x; + Assert.Equal(2, d.Count); + Assert.Equal("JÔÖú@2x.jpg", d.ObjectForKey("path").ToString()); + Assert.Equal("QÔÖú@2x 啕.jpg", d.ObjectForKey("Key QÔÖª@2x 䌡").ToString()); + } + +} } diff --git a/plist-cil.test/plist-cil.test.csproj b/plist-cil.test/plist-cil.test.csproj index 8057e2f..c695a2b 100644 --- a/plist-cil.test/plist-cil.test.csproj +++ b/plist-cil.test/plist-cil.test.csproj @@ -90,6 +90,11 @@ False PreserveNewest + + test-files\test-ascii-utf8.plist + False + PreserveNewest + PreserveNewest diff --git a/plist-cil/ASCIIPropertyListParser.cs b/plist-cil/ASCIIPropertyListParser.cs index 65f9c9e..8f139ea 100644 --- a/plist-cil/ASCIIPropertyListParser.cs +++ b/plist-cil/ASCIIPropertyListParser.cs @@ -92,7 +92,7 @@ namespace Claunia.PropertyList /// When an error occurs during parsing. public static NSObject Parse(byte[] bytes) { - ASCIIPropertyListParser parser = new ASCIIPropertyListParser(bytes); + ASCIIPropertyListParser parser = new ASCIIPropertyListParser(Encoding.UTF8.GetString(bytes).ToCharArray()); return parser.Parse(); } @@ -235,7 +235,7 @@ namespace Claunia.PropertyList /** * Property list source data */ - byte[] data; + char[] data; /** * Current parsing index */ @@ -253,7 +253,7 @@ namespace Claunia.PropertyList /// Creates a new parser for the given property list content. /// /// The content of the property list that is to be parsed. - ASCIIPropertyListParser(byte[] propertyListContent) + ASCIIPropertyListParser(char[] propertyListContent) { data = propertyListContent; } @@ -311,7 +311,7 @@ namespace Claunia.PropertyList for (int i = 1; i < expectedSymbols.Length; i++) excString += " or '" + expectedSymbols[i] + "'"; - excString += " but found '" + (char)data[index] + "'"; + excString += " but found '" + data[index] + "'"; throw new FormatException(String.Format("{0} at {1}", excString, index)); } } @@ -407,7 +407,7 @@ namespace Claunia.PropertyList string s = ""; while (!Accept(symbols)) { - s += (char)data[index]; + s += data[index]; Skip(); } return s; @@ -423,7 +423,7 @@ namespace Claunia.PropertyList String s = ""; while (!Accept(symbol)) { - s += (char)data[index]; + s += data[index]; Skip(); } return s; @@ -463,19 +463,19 @@ namespace Claunia.PropertyList { switch (data[index]) { - case (byte)ARRAY_BEGIN_TOKEN: + case ARRAY_BEGIN_TOKEN: { return ParseArray(); } - case (byte)DICTIONARY_BEGIN_TOKEN: + case DICTIONARY_BEGIN_TOKEN: { return ParseDictionary(); } - case (byte)DATA_BEGIN_TOKEN: + case DATA_BEGIN_TOKEN: { return ParseData(); } - case (byte)QUOTEDSTRING_BEGIN_TOKEN: + case QUOTEDSTRING_BEGIN_TOKEN: { string quotedString = ParseQuotedString(); //apple dates are quoted strings of length 20 and after the 4 year digits a dash is found @@ -690,7 +690,7 @@ namespace Claunia.PropertyList //Read from opening quotation marks to closing quotation marks and skip escaped quotation marks while (data[index] != QUOTEDSTRING_END_TOKEN || (data[index - 1] == QUOTEDSTRING_ESCAPE_TOKEN && unescapedBackslash)) { - quotedString += (char)data[index]; + quotedString += data[index]; if (Accept(QUOTEDSTRING_ESCAPE_TOKEN)) { unescapedBackslash = !(data[index - 1] == QUOTEDSTRING_ESCAPE_TOKEN && unescapedBackslash); @@ -739,8 +739,7 @@ namespace Claunia.PropertyList } default: { //a normal ASCII char - strBytes.Add((byte)0); - strBytes.Add((byte)c.Current); + strBytes.AddRange(Encoding.BigEndianUnicode.GetBytes(new[] { c.Current })); break; } } diff --git a/test-files/test-ascii-utf8.plist b/test-files/test-ascii-utf8.plist new file mode 100644 index 0000000..00ecac5 --- /dev/null +++ b/test-files/test-ascii-utf8.plist @@ -0,0 +1,5 @@ +// !$*UTF8*$! +{ + path = "JÔÖú@2x.jpg"; + "Key QÔÖª@2x \u4321" = "QÔÖú@2x 啕.jpg"; +} \ No newline at end of file