Skip to content

Commit

Permalink
escape spaces found while parsing GPO XMLNS tags
Browse files Browse the repository at this point in the history
  • Loading branch information
willchenmark committed Jan 6, 2025
1 parent 9233e1c commit eddd1b2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions salt/modules/win_lgpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eddd1b2

Please sign in to comment.