Skip to content

Commit

Permalink
Merge pull request #48 from madig/preserve-empty-strings
Browse files Browse the repository at this point in the history
Preserve empty strings
  • Loading branch information
anthrotype committed May 22, 2018
2 parents 7b51274 + bdd4cf7 commit dd81e46
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/ufonormalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,8 @@ def _convertPlistElementToObject(element):
else:
obj[key] = _convertPlistElementToObject(subElement)
elif tag == "string":
if not element.text:
return ""
return xmlEscapeText(element.text)
elif tag == "data":
return plistlib.Data.fromBase64(element.text)
Expand Down
2 changes: 2 additions & 0 deletions tests/data/glif/format1.glif
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
</outline>
<lib>
<dict>
<key>abc</key>
<string></string>
<key>com.letterror.somestuff</key>
<string>arbitrary custom data!</string>
</dict>
Expand Down
2 changes: 2 additions & 0 deletions tests/data/glif/format2.glif
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<guideline name="overshoot" y="-12"/>
<lib>
<dict>
<key>abc</key>
<string></string>
<key>com.letterror.somestuff</key>
<string>arbitrary custom data!</string>
<key>public.markColor</key>
Expand Down
12 changes: 10 additions & 2 deletions tests/test_ufonormalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def __exit__(self, exc, value, tb):
</outline>
<lib>
<dict>
<key>abc</key>
<string></string>
<key>com.letterror.somestuff</key>
<string>arbitrary custom data!</string>
</dict>
Expand Down Expand Up @@ -142,6 +144,8 @@ def __exit__(self, exc, value, tb):
<guideline name="overshoot" y="-12"/>
<lib>
<dict>
<key>abc</key>
<string></string>
<key>com.letterror.somestuff</key>
<string>arbitrary custom data!</string>
<key>public.markColor</key>
Expand Down Expand Up @@ -749,6 +753,8 @@ def test_normalizeGLIF_lib_defined(self):
<dict>
<key>foo</key>
<string>bar</string>
<key>abc</key>
<string></string>
</dict>
</lib>
'''.strip()
Expand All @@ -757,8 +763,10 @@ def test_normalizeGLIF_lib_defined(self):
_normalizeGlifLib(element, writer)
self.assertEqual(
writer.getText(),
'<lib>\n\t<dict>\n\t\t<key>foo</key>\n\t\t<string>bar</string>'
'\n\t</dict>\n</lib>')
'<lib>\n\t<dict>\n'
'\t\t<key>abc</key>\n\t\t<string></string>\n'
'\t\t<key>foo</key>\n\t\t<string>bar</string>\n'
'\t</dict>\n</lib>')

def test_normalizeGLIF_lib_undefined(self):
element = ET.fromstring("<lib></lib>")
Expand Down

0 comments on commit dd81e46

Please sign in to comment.