escape spaces found while parsing GPO XMLNS tags

This commit is contained in:
Will Sinatra 2025-01-06 16:40:39 -05:00 committed by Daniel Wozniak
parent c4a1a6eeba
commit a887a0000b

View file

@ -5060,6 +5060,16 @@ def _remove_invalid_xmlns(xml_file):
xml_tree = lxml.etree.parse(io.StringIO(modified_xml))
return xml_tree
def _encode_xmlns_url(match):
"""
Escape spaces in xmlns urls
"""
before_xmlns = match.group(1)
xmlns = match.group(2)
url = match.group(3)
after_url = match.group(4)
encoded_url = re.sub(r'\s+', '%20', url)
return f'{before_xmlns}{xmlns}="{encoded_url}"{after_url}'
def _parse_xml(adm_file):
"""
@ -5107,6 +5117,8 @@ def _parse_xml(adm_file):
encoding = "utf-16"
raw = raw.decode(encoding)
for line in raw.split("\r\n"):
if 'xmlns="' in line:
line = re.sub(r'(.*)(\bxmlns(?::\w+)?)\s*=\s*"([^"]+)"(.*)', _encode_xmlns_url, line)
if 'key="' in line:
start = line.index('key="')
q1 = line[start:].index('"') + start