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

[3.12] gh-107715: Escape class name in regular expression (GH-107716) #107726

Merged
merged 2 commits into from
Aug 16, 2023

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Aug 7, 2023

This patch escapes the class name before embedding it in the regular expression
for pat in doctest.DocTestFinder._find_lineno. While class names do not
ordinarily contain special characters, it is possible to encounter these when a
class is created dynamically. Escaping the name will correctly return None in
this scenario, rather than potentially matching a different class or raising
re.error depending on the symbols used.
(cherry picked from commit 8579327)

Co-authored-by: Gertjan van Zwieten git@gjvz.nl

…7716)

This patch escapes the class name before embedding it in the regular expression
for `pat` in `doctest.DocTestFinder._find_lineno`. While class names do not
ordinarily contain special characters, it is possible to encounter these when a
class is created dynamically. Escaping the name will correctly return `None` in
this scenario, rather than potentially matching a different class or raising
`re.error` depending on the symbols used.
(cherry picked from commit 8579327)

Co-authored-by: Gertjan van Zwieten <git@gjvz.nl>
@cpython-cla-bot
Copy link

cpython-cla-bot bot commented Aug 7, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@Yhg1s Yhg1s merged commit ea68652 into python:3.12 Aug 16, 2023
@miss-islington miss-islington deleted the backport-8579327-3.12 branch August 16, 2023 12:29
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.

DocTestFinder.find fails if module contains class objects with special characters
5 participants