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

urllib.parse doesn't work with empty port #64469

Closed
serhiy-storchaka opened this issue Jan 15, 2014 · 2 comments
Closed

urllib.parse doesn't work with empty port #64469

serhiy-storchaka opened this issue Jan 15, 2014 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 20270
Nosy @orsenthil, @serhiy-storchaka
Files
  • urllib_parse_empty_port.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2014-01-18.16:33:04.857>
    created_at = <Date 2014-01-15.12:26:25.523>
    labels = ['type-bug', 'library']
    title = "urllib.parse doesn't work with empty port"
    updated_at = <Date 2014-01-18.16:33:04.857>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2014-01-18.16:33:04.857>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-01-18.16:33:04.857>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2014-01-15.12:26:25.523>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['33480']
    hgrepos = []
    issue_num = 20270
    keywords = ['patch']
    message_count = 2.0
    messages = ['208155', '208404']
    nosy_count = 3.0
    nosy_names = ['orsenthil', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue20270'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4']

    @serhiy-storchaka
    Copy link
    Member Author

    According to RFC 3986 the port subcomponent is defined as zero or more decimal digits delimited from the host by a single colon. I.e. 'python.org:' is valid (but not normalized) form. Empty port is equivalent to absent port.

    >>> import urllib.parse
    >>> p = urllib.parse.urlparse('http://python.org:')
    >>> p.hostname
    'python.org'
    >>> p.port  # should return None
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/serhiy/py/cpython-3.3/Lib/urllib/parse.py", line 156, in port
        port = int(port, 10)
    ValueError: invalid literal for int() with base 10: ''
    >>> urllib.parse.splitport('python.org:')  # should return ('python.org', None)
    ('python.org:', None)
    >>> urllib.parse.splitnport('python.org:')  # should return ('python.org', -1)
    ('python.org', None)
    >>> urllib.parse.splitnport('python.org:', 80)  # should return ('python.org', 80)
    ('python.org', None)

    Proposed patch fixes this. It also adds tests for urllib.parse.splitport().

    @serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 15, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 18, 2014

    New changeset a4a51a0d4575 by Serhiy Storchaka in branch '2.7':
    Issue bpo-20270: urllib and urlparse now support empty ports.
    http://hg.python.org/cpython/rev/a4a51a0d4575

    New changeset 52edc7087c81 by Serhiy Storchaka in branch '3.3':
    Issue bpo-20270: urllib.urlparse now supports empty ports.
    http://hg.python.org/cpython/rev/52edc7087c81

    New changeset 1469c4fde8cd by Serhiy Storchaka in branch 'default':
    Issue bpo-20270: urllib.urlparse now supports empty ports.
    http://hg.python.org/cpython/rev/1469c4fde8cd

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    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

    1 participant