From 337bb662119e19026e56c2913e15c1d03e339f2d Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 16 Dec 2019 12:05:13 +0000 Subject: [PATCH] glifLib: strip comments when parsing with lxml they are already ignored when parsing via built-in ElementTree --- Lib/fontTools/ufoLib/glifLib.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Lib/fontTools/ufoLib/glifLib.py b/Lib/fontTools/ufoLib/glifLib.py index 9a83fee40..b18ac4897 100755 --- a/Lib/fontTools/ufoLib/glifLib.py +++ b/Lib/fontTools/ufoLib/glifLib.py @@ -852,7 +852,11 @@ def validateLayerInfoVersion3Data(infoData): # ----------------- def _glifTreeFromFile(aFile): - root = etree.parse(aFile).getroot() + if etree._have_lxml: + tree = etree.parse(aFile, parser=etree.XMLParser(remove_comments=True)) + else: + tree = etree.parse(aFile) + root = tree.getroot() if root.tag != "glyph": raise GlifLibError("The GLIF is not properly formatted.") if root.text and root.text.strip() != '': @@ -862,7 +866,10 @@ def _glifTreeFromFile(aFile): def _glifTreeFromString(aString): data = tobytes(aString, encoding="utf-8") - root = etree.fromstring(data) + if etree._have_lxml: + root = etree.fromstring(data, parser=etree.XMLParser(remove_comments=True)) + else: + root = etree.fromstring(data) if root.tag != "glyph": raise GlifLibError("The GLIF is not properly formatted.") if root.text and root.text.strip() != '':