Skip to content

Commit ebb634b

Browse files
nglevinluispadron
authored andcommitted
Update plisttool to handle empty input plists, to allow for routing through strings and plists safely.
Cherry-pick: 9eb4232
1 parent e32bb8a commit ebb634b

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

tools/plisttool/plisttool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ def _read_plist(cls, plist_file, name, target):
774774
PlistToolError: if plutil return code is non-zero.
775775
"""
776776
plist_contents = plist_file.read()
777+
if not plist_contents:
778+
# If the incoming file is empty, return an empty dictionary.
779+
return {}
777780

778781
# Binary plists are easy to identify because they start with 'bplist'. For
779782
# plain text plists, it may be possible to have leading whitespace, but

tools/plisttool/plisttool_unittest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,19 @@ def test_merge_of_one_dict(self):
459459
self._assert_plisttool_result({'plists': [plist1]}, {'Foo': 'abc'})
460460

461461
def test_merge_of_one_empty_file(self):
462+
plist_fp = tempfile.NamedTemporaryFile(delete=False)
463+
self.addCleanup(lambda: os.unlink(path=plist_fp.name))
464+
self._assert_plisttool_result({'plists': [plist_fp.name]}, {})
465+
466+
def test_merge_of_one_empty_file_with_binary_output(self):
467+
plist_fp = tempfile.NamedTemporaryFile(delete=False)
468+
self.addCleanup(lambda: os.unlink(path=plist_fp.name))
469+
self._assert_plisttool_result({
470+
'binary': True,
471+
'plists': [plist_fp.name],
472+
}, {})
473+
474+
def test_merge_of_one_empty_xml_file(self):
462475
plist1 = _xml_plist('')
463476
self._assert_plisttool_result({'plists': [plist1]}, {})
464477

0 commit comments

Comments
 (0)