FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix: is_fully_escaped does not handle consecutive backslashes correctly · Issue #14392 · pytest-dev/pytest · GitHub

Fix: is_fully_escaped does not handle consecutive backslashes correctly #14392

Description

Bug

The function \is_fully_escaped\ in \src/_pytest/raises.py\ only checks whether the character immediately before a regex metacharacter is a backslash. It does not count how many consecutive backslashes precede the metacharacter.

When two backslashes appear before a metacharacter (e.g.
'\\.'), the first backslash escapes the second, so the metacharacter is left unescaped. But \is_fully_escaped\ sees a backslash before the dot and incorrectly reports the string as fully escaped.

Impact

This affects \pytest.raises(match=...)\ when the match pattern contains escaped backslashes followed by a regex metacharacter. The match failure message may skip showing a regex diff and instead show a less helpful message.

Reproduction

\\python
from _pytest.raises import is_fully_escaped

Should be False: two backslashes escape each other, leaving . unescaped

is_fully_escaped(r'\\.') # Returns True (wrong)

Should be False: four backslashes = two escaped pairs, | unescaped

is_fully_escaped('\\\\|') # Returns True (wrong)
\\

Expected behavior

Count consecutive backslashes. If the count is even, the metacharacter is not escaped. If odd, it is escaped.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL