Skip to content

Commit

Permalink
Merge pull request #117 from gisce/fix_xml_objectify_null_chars
Browse files Browse the repository at this point in the history
FIX - Delete null chars from the xml files
  • Loading branch information
tinogis authored Nov 7, 2024
2 parents b2e6c0f + dc53ec3 commit 92cb700
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion primestg/message.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import re

from lxml.etree import XMLSyntaxError
from lxml.objectify import fromstring
import binascii
import zlib
Expand Down Expand Up @@ -54,7 +57,16 @@ def objectified(self, value):
self._xml = value.decode('iso-8859-15')
except:
self._xml = value
self._objectified = fromstring(self._xml)

# If there is null chars on the XML string, delete it
try:
xml = fromstring(self._xml)
except XMLSyntaxError as e:
# Delete everything from the first null char until the next double quote char '"'
xml_string = re.sub(r'[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F].*?"', '"', self._xml)
xml = fromstring(xml_string)

self._objectified = xml


class MessageS(BaseMessage):
Expand Down

0 comments on commit 92cb700

Please sign in to comment.