Skip to content

Commit

Permalink
Merge pull request #47 from belluzj/fix-crash-plist-data
Browse files Browse the repository at this point in the history
Fix crash in normalization of data in lib
  • Loading branch information
anthrotype authored May 2, 2018
2 parents 5f537f3 + c396089 commit a651acd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ufonormalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def main(args=None):
if hasattr(plistlib, "loads"):

def _loads(data):
return plistlib.loads(data)
return plistlib.loads(data, use_builtin_types=False)

def _dumps(plist):
return plistlib.dumps(plist)
Expand Down
32 changes: 32 additions & 0 deletions tests/test_ufonormalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import shutil
import datetime
import plistlib
import base64
from io import open
from xml.etree import cElementTree as ET
from ufonormalizer import (
Expand Down Expand Up @@ -1524,6 +1525,37 @@ def test_main_float_precision_argument(self):
data = subpathReadPlist(outdir, "lib.plist")
self.assertEqual(data["test_float"], 0.3333333333333334)

def test_normalizeLibPlistWithBytesData(self):
metainfo = METAINFO_PLIST % 3
libdata = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>org.robofab.fontlab.customdata</key>
<data>
gAJ9cQFVA2xpYnECY3BsaXN0bGliCl9JbnRlcm5hbERpY3QKcQMpgXEEVSdj
b20uc2NocmlmdGdlc3RhbHR1bmcuR2x5cGhzLmxhc3RDaGFuZ2VxBVUTMjAx
Ny8wOS8yNiAwOToxMzoyMXEGc31xB2JzLg==
</data>
</dict>
</plist>
"""
with TemporaryDirectory(suffix=".ufo") as indir:
outdir = os.path.join(indir, 'output.ufo')

subpathWriteFile(metainfo, indir, "metainfo.plist")
subpathWriteFile(libdata, indir, "lib.plist")

main(["-o", outdir, indir])
data = subpathReadPlist(outdir, "lib.plist")
self.assertEqual(
data['org.robofab.fontlab.customdata'],
base64.b64decode("""\
gAJ9cQFVA2xpYnECY3BsaXN0bGliCl9JbnRlcm5hbERpY3QKcQMpgXEEVSdj
b20uc2NocmlmdGdlc3RhbHR1bmcuR2x5cGhzLmxhc3RDaGFuZ2VxBVUTMjAx
Ny8wOS8yNiAwOToxMzoyMXEGc31xB2JzLg==
"""))


class XMLWriterTest(unittest.TestCase):
def __init__(self, methodName):
Expand Down

0 comments on commit a651acd

Please sign in to comment.