Skip to content

Bug in python >= 2.7 with urllib2 fragment #55912

Closed

Description

@IvanIvanenko
BPO 11703
Nosy @orsenthil, @asvetlov
Files
  • issue11703_py27.patch: Patch against 2.7
  • issue11703_py31.patch: Patch against 3.1
  • issue11703_py27_with_redirect.patch: Patch against 2.7
  • issue11703_py31_with_redirect.patch: Patch against 3.1
  • 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 = 'https://github.com/orsenthil'
    closed_at = <Date 2011-04-12.23:38:52.024>
    created_at = <Date 2011-03-28.21:23:30.472>
    labels = ['type-bug', 'library']
    title = 'Bug in python >= 2.7 with urllib2 fragment'
    updated_at = <Date 2011-04-13.01:47:53.941>
    user = 'https://bugs.python.org/IvanIvanenko'

    bugs.python.org fields:

    activity = <Date 2011-04-13.01:47:53.941>
    actor = 'python-dev'
    assignee = 'orsenthil'
    closed = True
    closed_date = <Date 2011-04-12.23:38:52.024>
    closer = 'orsenthil'
    components = ['Library (Lib)']
    creation = <Date 2011-03-28.21:23:30.472>
    creator = 'Ivan.Ivanenko'
    dependencies = []
    files = ['21456', '21457', '21555', '21556']
    hgrepos = []
    issue_num = 11703
    keywords = ['patch']
    message_count = 11.0
    messages = ['132423', '132497', '132508', '132613', '133183', '133620', '133621', '133624', '133625', '133634', '133635']
    nosy_count = 5.0
    nosy_names = ['orsenthil', 'asvetlov', 'santoso.wijaya', 'python-dev', 'Ivan.Ivanenko']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue11703'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2', 'Python 3.3']

    Activity

    1. IvanIvanenko commented on Mar 28, 2011

      IvanIvanenkomannequin
      MannequinAuthor
      result = urllib.urlopen("http://docs.python.org/library/urllib.html#OK")
      print result.geturl()
      
      result = urllib2.urlopen("http://docs.python.org/library/urllib.html#OK")
      print result.geturl()

      Python 2.6 returns:
      "http://docs.python.org/library/urllib.html#OK"
      "http://docs.python.org/library/urllib.html#OK"

      Python 2.7 returns:
      "http://docs.python.org/library/urllib.html#OK"
      "http://docs.python.org/library/urllib.html"

      2to3 -w test.py
      Python 3 returns:
      "http://docs.python.org/library/urllib.html"
      "http://docs.python.org/library/urllib.html"

      I expect geturl() result with "#OK" in all cases

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Mar 28, 2011
    3. santosowijaya commented on Mar 29, 2011

      santosowijayamannequin
      Mannequin

      This is because the Request class' constructor splits the URL into __original and fragment:

          def __init__(self, url, data=None, headers={},
                       origin_req_host=None, unverifiable=False):
              # unwrap('<URL:type://host/path>') --> 'type://host/path'
              self.__original = unwrap(url)
              self.__original, fragment = splittag(self.__original)

      And the construction of object that urlopen() returns has its geturl() returns the request object's __original field (by now, minus the fragment).

    4. santosowijaya commented on Mar 29, 2011

      santosowijayamannequin
      Mannequin

      Attaching patches against 2.7 and 3.1 branches.

    5. IvanIvanenko commented on Mar 30, 2011

      IvanIvanenkomannequin
      MannequinAuthor
    6. santosowijaya commented on Apr 6, 2011

      santosowijayamannequin
      Mannequin

      It already does. ;-)

      Python 2.7.1+ (default, Apr  6 2011, 16:25:38) [MSC v.1500 32 bit (Intel)] on wi
      n32
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import urllib2
      [74578 refs]
      >>> fp = urllib2.urlopen('http://16.foobnix-cms.appspot.com/test_base')
      [75643 refs]
      >>> fp.geturl()
      "http://16.foobnix-cms.appspot.com/test_redirect#json={value:'OK'}"
      [75645 refs]

      I'm attaching patches with the appropriate unittest for the redirected case, though.

    7. python-dev commented on Apr 12, 2011

      python-devmannequin
      Mannequin

      New changeset 3f240a1cd245 by Senthil Kumaran in branch '3.1':
      Fix bpo-11703 - urllib2.geturl() does not return correct url when the original url contains #fragment. Patch Contribution by Santoso Wijaya.
      http://hg.python.org/cpython/rev/3f240a1cd245

    8. orsenthil commented on Apr 12, 2011

      @orsenthil
      Member

      It should be noted that the bug surfaced in 2.7 and above due to changes made as part of bpo-8280.

    9. self-assigned this
      on Apr 12, 2011
    10. python-dev commented on Apr 12, 2011

      python-devmannequin
      Mannequin

      New changeset 6e73f75ee034 by Senthil Kumaran in branch '2.7':
      Fix bpo-11703 - urllib2.get_url does not handle fragment in url properly.
      http://hg.python.org/cpython/rev/6e73f75ee034

    11. orsenthil commented on Apr 12, 2011

      @orsenthil
      Member

      This is fixed in all the codelines. Thanks for the patch, Santoso.

    12. python-dev commented on Apr 13, 2011

      python-devmannequin
      Mannequin

      New changeset 8ee48ec69844 by Senthil Kumaran in branch '3.1':
      Update the News for the fix to bpo-11703.
      http://hg.python.org/cpython/rev/8ee48ec69844

    13. python-dev commented on Apr 13, 2011

      python-devmannequin
      Mannequin

      New changeset 502bb809b03b by Senthil Kumaran in branch '2.7':
      update news in 2.7 for Issue bpo-11703
      http://hg.python.org/cpython/rev/502bb809b03b

    14. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    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