Skip to content

netrc treats empty quoted tokens as end-of-file #155468

Description

@lpyu001

Bug description

netrc does not distinguish an empty quoted token ("") from end-of-file. When an empty token appears where a top-level or follower token is expected, parsing stops successfully and silently ignores the remaining content. It should raise netrc.NetrcParseError instead.

Reproduction code

import netrc
import tempfile
from pathlib import Path

with tempfile.TemporaryDirectory() as directory:
    path = Path(directory) / "test.netrc"
    path.write_text(
        '"" invalid\n'
        'machine example.com login alice password secret\n',
        encoding="utf-8",
    )

    parsed = netrc.netrc(path)
    print(parsed.hosts)  

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions