diff options
author | Martin Weinelt <mweinelt@users.noreply.github.com> | 2023-05-03 09:28:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-03 09:28:32 +0200 |
commit | abc97d3572dec126eba9fec358eb2f359a944683 (patch) | |
tree | 91c2a50a791c3b8acf204ba2ee43342192e7001f | |
parent | a63e964786a2b317a320200fab3e4288b1c59241 (diff) | |
parent | 56a07ba986de50006d24792615ee8609342c0354 (diff) |
Merge pull request #226937 from rhendric/rhendric/update-python-libraries
update-python-libraries: escape vars in regexes
-rwxr-xr-x | pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py b/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py index 14b3ed4f3f1e4..42ebd89143eef 100755 --- a/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py +++ b/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py @@ -65,7 +65,7 @@ def _get_values(attribute, text): :returns: List of matches. """ - regex = '{}\s+=\s+"(.*)";'.format(attribute) + regex = '{}\s+=\s+"(.*)";'.format(re.escape(attribute)) regex = re.compile(regex) values = regex.findall(text) return values @@ -103,9 +103,9 @@ def _get_unique_value(attribute, text): def _get_line_and_value(attribute, text, value=None): """Match attribute in text. Return the line and the value of the attribute.""" if value is None: - regex = rf'({attribute}\s+=\s+\"(.*)\";)' + regex = rf'({re.escape(attribute)}\s+=\s+\"(.*)\";)' else: - regex = rf'({attribute}\s+=\s+\"({value})\";)' + regex = rf'({re.escape(attribute)}\s+=\s+\"({re.escape(value)})\";)' regex = re.compile(regex) results = regex.findall(text) n = len(results) |