From c0fba39133cbb95eab2537cbfea849120b200517 Mon Sep 17 00:00:00 2001 From: vectorsigma72 Date: Wed, 3 Jun 2020 16:41:01 +0200 Subject: [PATCH] Decode/Encode xml characters in the Plist Editor --- CloverApp/Clover/Extensions.swift | 9 +++++---- .../Clover/Plist Editor/PE_Conversions.swift | 18 +++++++++--------- .../Clover/Plist Editor/PlistParser.swift | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/CloverApp/Clover/Extensions.swift b/CloverApp/Clover/Extensions.swift index ac986aac6..1adc91aef 100644 --- a/CloverApp/Clover/Extensions.swift +++ b/CloverApp/Clover/Extensions.swift @@ -174,9 +174,9 @@ extension String { return UnsafePointer(buffer) } - /// Escape XML special characthers such: + /// Encode XML special characthers such: /// & as &, \ as ", ' as &apos, < as <, and > as > - var escapingXMLCharacters: String { + var encodingXMLCharacters: String { get { /* " " @@ -192,13 +192,14 @@ extension String { s = s.replacingOccurrences(of: "'", with: "'") s = s.replacingOccurrences(of: "<", with: "<") s = s.replacingOccurrences(of: ">", with: ">") + print(s) return s } } - /// Convert XML characters such: + /// Decode XML characters such: /// & to &, " to \ , ' to &apos, < to <, and > to > - var convertingXMLCharacters: String { + var decodingXMLCharacters: String { get { /* " " diff --git a/CloverApp/Clover/Plist Editor/PE_Conversions.swift b/CloverApp/Clover/Plist Editor/PE_Conversions.swift index d0c3ba830..6fed09f90 100644 --- a/CloverApp/Clover/Plist Editor/PE_Conversions.swift +++ b/CloverApp/Clover/Plist Editor/PE_Conversions.swift @@ -50,7 +50,7 @@ func gConvertPENodeToPlist(node: PENode?) -> String { plist = xml1Header + "\n" + gSerializeNodeToPlist(node: node!, file: "", indentation: 0) + xml1Footer } } else if type == .String { - plist = xml1Header + "\n" + "" + (ro.value as! String) + "" + "\n" + xml1Footer + plist = xml1Header + "\n" + "" + (ro.value as! String).encodingXMLCharacters + "" + "\n" + xml1Footer } else if type == .Data { let data = ro.value as! NSData let strBase64 : String = (data as Data).base64EncodedString(options: .endLineWithLineFeed) @@ -89,7 +89,7 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri if type == .Dictionary { if !isRoot { if node.peparent != nil && node.peparent!.tagdata!.type != .Array { - str += indent + "" + node.tagdata!.key + "" + "\n" + str += indent + "" + node.tagdata!.key.encodingXMLCharacters + "" + "\n" } } else { str = "\n" @@ -120,7 +120,7 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri } } else if type == .Array { if !isRoot { - str += indent + "" + node.tagdata!.key + "" + "\n" + str += indent + "" + node.tagdata!.key.encodingXMLCharacters + "" + "\n" } else { str = "\n" } @@ -153,14 +153,14 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri hi */ if node.peparent!.tagdata!.type != .Array { - str = str + indent + "" + node.tagdata!.key + "" + "\n" + str = str + indent + "" + node.tagdata!.key.encodingXMLCharacters + "" + "\n" } else if isRoot { str = str + indent + "" + localizedNewItem + "" + "\n" } - str = str + indent + "" + (node.tagdata!.value as! String) + "" + "\n" + str = str + indent + "" + (node.tagdata!.value as! String).encodingXMLCharacters + "" + "\n" } else if type == .Data { if node.peparent!.tagdata!.type != .Array { - str = str + indent + "" + node.tagdata!.key + "" + "\n" + str = str + indent + "" + node.tagdata!.key.encodingXMLCharacters + "" + "\n" } else if isRoot { str = str + indent + "" + localizedNewItem + "" + "\n" } @@ -169,14 +169,14 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri str = str + indent + "" + strBase64 + "" + "\n" } else if type == .Date { if node.peparent!.tagdata!.type != .Array { - str = str + indent + "" + node.tagdata!.key + "" + "\n" + str = str + indent + "" + node.tagdata!.key.encodingXMLCharacters + "" + "\n" } else if isRoot { str = str + indent + "" + localizedNewItem + "" + "\n" } str = str + indent + "" + utcDateToString(node.tagdata!.value as! Date) + "" + "\n" } else if type == .Number { if node.peparent!.tagdata!.type != .Array { - str = str + indent + "" + node.tagdata!.key + "" + "\n" + str = str + indent + "" + node.tagdata!.key.encodingXMLCharacters + "" + "\n" } else if isRoot { str = str + indent + "" + localizedNewItem + "" + "\n" } @@ -190,7 +190,7 @@ func gSerializeNodeToPlist(node: PENode, file: String, indentation: Int) -> Stri } } else if type == .Bool { if node.peparent!.tagdata!.type != .Array { - str = str + indent + "" + node.tagdata!.key + "" + "\n" + str = str + indent + "" + node.tagdata!.key.encodingXMLCharacters + "" + "\n" } else if isRoot { str = str + indent + "" + localizedNewItem + "" + "\n" } diff --git a/CloverApp/Clover/Plist Editor/PlistParser.swift b/CloverApp/Clover/Plist Editor/PlistParser.swift index b0d0f6c12..8059fd34f 100644 --- a/CloverApp/Clover/Plist Editor/PlistParser.swift +++ b/CloverApp/Clover/Plist Editor/PlistParser.swift @@ -331,10 +331,10 @@ final class PlistParser: NSObject, XMLParserDelegate { self.goback() break case "key": - self.currentNode?.tagdata?.key = value?.escapingXMLCharacters ?? "" + self.currentNode?.tagdata?.key = value?.decodingXMLCharacters ?? "" break case "string": - self.currentNode?.tagdata?.value = value!.escapingXMLCharacters + self.currentNode?.tagdata?.value = value!.decodingXMLCharacters self.currentNode?.tagdata?.type = .String self.goback() break