From a6780902d3118d59cb99ab694a5469d5b3d0959f Mon Sep 17 00:00:00 2001 From: Mark Hatchell Date: Sat, 13 Dec 2014 14:27:12 -0500 Subject: [PATCH] There was a bug I found where the parser would not properly close the hierarchy if there was a non self closing empty array "". The fix was in two places, one where the file is first accessed. Added a preg_replace on the XML data before parsing that replaces non self closing empty array elements with self closing elements. The second is in the parsing of the array element. Test for empty array element if found gracefully skip it. --- classes/parsers/plist/PlistParser.inc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/classes/parsers/plist/PlistParser.inc b/classes/parsers/plist/PlistParser.inc index 412781b..f3df7ec 100644 --- a/classes/parsers/plist/PlistParser.inc +++ b/classes/parsers/plist/PlistParser.inc @@ -7,7 +7,6 @@ class plistParser extends XMLReader 'plistParser::parse() is deprecated, please use plistParser::parseFile()', E_USER_NOTICE ); - return $this->parseFile($file); } @@ -15,7 +14,10 @@ class plistParser extends XMLReader if(basename($file) == $file) { throw new Exception("Non-relative file path expected", 1); } - $this->open("file://" . $file); + $fileData = file_get_contents("file://" .$file); + //replaces non self closing empty array elements with self closing elements + $fileData = preg_replace('/\s+<\/array>/ism','',$fileData); + $this->xml($fileData); return $this->process(); } @@ -79,7 +81,15 @@ class plistParser extends XMLReader return false; break; case 'array': - return $this->parse_array(); + //tests for empty arrays and gracefully moves on keeping the structure of the document intact. + $tmpAarrayTest = $this->readInnerXML(); + $tmpAarrayTest = trim($tmpAarrayTest); + if (empty($tmpAarrayTest)) { + return array(); + } else { + return $this->parse_array(); + } + $tmpAarrayTest = null; break; case 'dict': return $this->parse_dict();