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

gh-99080: Preserve backslash character not used to escape quotes in .netrc files by stefanoboriero · Pull Request #99088 · python/cpython · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 3 additions & 2 deletions Lib/netrc.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def get_token(self):
if ch == '"':
return token
elif ch == "\\":
backslash = ch
ch = self._read_char()
if ch != '"':
token += backslash
token += ch
else:
if ch == "\\":
Expand All @@ -54,8 +57,6 @@ def get_token(self):
for ch in fiter:
if ch in self.whitespace:
return token
elif ch == "\\":
ch = self._read_char()
token += ch
return token

Expand Down
22 changes: 22 additions & 0 deletions Lib/test/test_netrc.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,28 @@ def test_token_value_non_ascii(self):
machine host.domain.com login log password \xa1\xa2 account acct
""", 'password', '\xa1\xa2')

def test_token_value_with_backslash(self):
self._test_token_x("""\
machine host.domain.com login lo\gin password pass account acct
""", 'login', 'lo\gin')
self._test_token_x("""\
machine host.domain.com login log password pass account \account
""", 'account', '\account')
self._test_token_x("""\
machine host.domain.com login log password pass\word account acct
""", 'password', 'pass\word')

def test_token_value_with_backslash_enclosed_in_quotes(self):
self._test_token_x("""\
machine host.domain.com login "lo\gin" password pass account acct
""", 'login', 'lo\gin')
self._test_token_x("""\
machine host.domain.com login log password pass account "acc\ount"
""", 'account', 'acc\ount')
self._test_token_x("""\
machine host.domain.com login log password "pass\word" account acct
""", 'password', 'pass\word')

def test_token_value_leading_hash(self):
self._test_token_x("""\
machine host.domain.com login #log password pass account acct
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Treat backslashes in .netrc files as escaping characters only for quotes in quotes

Back | FazBrowse Home | New Git URL