Skip to content

Commit

Permalink
Fix extracting references from regex match
Browse files Browse the repository at this point in the history
The regex uses separate capture groups for alternative expressions that
match a single-quoted or a double-quoted string. This is more robust
with strings that may contain quotes.

However the code using the match objects doesn't currently take the two
capture groups into account and always expects the results in group 1,
which only matches double-quoted strings.

This change introduces a check so that if group 1 is None, the function
will use the matched substring in group 2.

Closes arthepsy#36
  • Loading branch information
ikey8k committed Nov 3, 2022
1 parent da771a4 commit c5dede6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion gp-okta.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def err(s):
sys.exit(1)

def _remx(c, v): return re.search(r'\s*' + v + r'\s*"?[=:]\s*(?:"((?:[^"\\]|\\.)*)"|\'((?:[^\'\\]|\\.)*)\')', c)
_refx = lambda mx: to_b(mx.group(1)).decode('unicode_escape').strip()
_refx = lambda mx: to_b(mx.group(1) if mx.group(1) is not None else mx.group(2)).decode('unicode_escape').strip()

def parse_xml(xml):
# type: (str) -> etree._Element
Expand Down

0 comments on commit c5dede6

Please sign in to comment.