Skip to content

gh-155468: Distinguish empty quoted tokens from EOF in netrc - #155471

Open
lpyu001 wants to merge 1 commit into
python:mainfrom
lpyu001:netrc
Open

gh-155468: Distinguish empty quoted tokens from EOF in netrc#155471
lpyu001 wants to merge 1 commit into
python:mainfrom
lpyu001:netrc

Conversation

@lpyu001

@lpyu001 lpyu001 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Comment thread Lib/netrc.py
lexer.instream.readline()
continue
if tt in {'', 'machine', 'default', 'macdef'}:
if tt is None or tt in {'machine', 'default', 'macdef'}:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yu can to "tt in {None, "machine", ...}

Comment thread Lib/netrc.py
break
elif tt == 'login' or tt == 'user':
login = lexer.get_token()
if login is None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need thsoe None checks, just do login = lexer.get_token() or ""

Comment thread Lib/test/test_netrc.py
def test_empty_quoted_token_is_not_eof(self):
data = (
'"" invalid',
'machine host.domain.com "" invalid',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also test what happens when you put "" at the end (e.g., machine host.domain.com invalid "") Those should be legitimate cases but they are not tested.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants