Skip to content

Commit 80925bd

Browse files
committed
pvesh: Fix invalid string escape sequences
In Python, only a [limited set of characters][0] can be escaped with a backslash. In recent versions of Python, attempting to escape a non-escapeable character [raises a SyntaxWarning][1], polluting the playbook output with warnings like: <unknown>:59: SyntaxWarning: invalid escape sequence '\(' <unknown>:60: SyntaxWarning: invalid escape sequence '\.' <unknown>:61: SyntaxWarning: invalid escape sequence '\.' This commit adds the string literal prefix 'r' to regular expressions in pvesh.py to ensure that escape sequences are not interpreted in the given strings. As there were no valid escape sequences in those strings to begin with, the actual string content remains the same. [0]: https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences [1]: python/cpython#98401
1 parent bbc1e1f commit 80925bd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

module_utils/pvesh.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def run_command(handler, resource, **params):
5656

5757
if handler == "get":
5858
if any(re.match(pattern, stderr[0]) for pattern in [
59-
"^no such user \('.{3,64}?'\)$",
60-
"^(group|role|pool) '[A-Za-z0-9\.\-_]+' does not exist$",
61-
"^domain '[A-Za-z][A-Za-z0-9\.\-_]+' does not exist$"]):
59+
r"^no such user \('.{3,64}?'\)$",
60+
r"^(group|role|pool) '[A-Za-z0-9\.\-_]+' does not exist$",
61+
r"^domain '[A-Za-z][A-Za-z0-9\.\-_]+' does not exist$"]):
6262
return {u"status": 404, u"message": stderr[0]}
6363

6464
# This will occur when a param is invalid

0 commit comments

Comments
 (0)