Skip to content

netrc.py strips away valid backslash characters from tokens #99080

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

Open
stefanoboriero opened this issue Nov 3, 2022 · 1 comment
Open

netrc.py strips away valid backslash characters from tokens #99080

stefanoboriero opened this issue Nov 3, 2022 · 1 comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@stefanoboriero
Copy link

stefanoboriero commented Nov 3, 2022

Bug report

Commit 15409c7 to close PR #26330 introduced a regression in the stdlib netrc.py that causes backslashes to be stripped out of tokens. As an example, the password extracted from the following .netrc file

machine my.host.com login user password mypass\word

will be mypassword instead of mypass\word. Same behavior would happen for login or account tokens.

Your environment

  • CPython versions tested on: >=3.11
@stefanoboriero stefanoboriero added the type-bug An unexpected behavior, bug, or error label Nov 3, 2022
@ericvsmith
Copy link
Member

Here's a reproducer:

import netrc

filename = 'netrctest'

with open(filename, 'w') as fl:
    print(r'machine my.host.com login user password mypass\word', file=fl)

n = netrc.netrc(filename)
print(n.hosts)

With 3.9.10:

{'my.host.com': ('user', None, 'mypass\\word')}

With 3.12.0a0:

{'my.host.com': ('user', '', 'mypassword')}

stefanoboriero added a commit to stefanoboriero/cpython that referenced this issue Nov 4, 2022
Backslashes can be valid characters in password, they are not always
used to escape symbols.
Treat backslash characters as escape symbols only for quotes in quotes.
@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants