Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pvesh: Fix invalid string escape sequences #244

Merged
merged 1 commit into from
Jul 1, 2024
Merged

Conversation

tbabej
Copy link
Contributor

@tbabej tbabej commented Jun 5, 2024

In Python, only a limited set of characters can be escaped with a backslash. In recent versions of Python, attempting to escape a non-escapeable character raises a SyntaxWarning, 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.

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
@lae
Copy link
Owner

lae commented Jul 1, 2024

Huh, I don't know how I missed this PR. Thanks!

@lae lae merged commit 45ebf01 into lae:develop Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants