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

SimpleHTTPServer serves files even if the URL has a trailing slash #61526

Closed
larryhastings opened this issue Mar 1, 2013 · 7 comments
Closed
Assignees
Labels
easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@larryhastings
Copy link
Contributor

BPO 17324
Nosy @orsenthil, @larryhastings, @karlcow, @vajrasky
Files
  • issue-17324-test-1.patch
  • patch_for_fixing_the_server_serving_the_url_with_trailing_slash.txt: Patch to fix the server should not serve the file which exists but with the trailing slash
  • 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 2013-09-13.07:24:26.621>
    created_at = <Date 2013-03-01.08:54:06.179>
    labels = ['easy', 'type-bug', 'library']
    title = 'SimpleHTTPServer serves files even if the URL has a trailing slash'
    updated_at = <Date 2013-09-13.07:24:26.619>
    user = 'https://github.com/larryhastings'

    bugs.python.org fields:

    activity = <Date 2013-09-13.07:24:26.619>
    actor = 'orsenthil'
    assignee = 'orsenthil'
    closed = True
    closed_date = <Date 2013-09-13.07:24:26.621>
    closer = 'orsenthil'
    components = ['Library (Lib)']
    creation = <Date 2013-03-01.08:54:06.179>
    creator = 'larry'
    dependencies = []
    files = ['29329', '30863']
    hgrepos = []
    issue_num = 17324
    keywords = ['patch', 'easy']
    message_count = 7.0
    messages = ['183247', '183263', '183598', '192439', '192669', '197555', '197556']
    nosy_count = 6.0
    nosy_names = ['orsenthil', 'larry', 'karlcow', 'python-dev', 'vajrasky', 'senko']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue17324'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4']

    @larryhastings
    Copy link
    Contributor Author

    To reproduce:

    1. Create a file called "foo.txt" in the local directory, put whatever you like in it.
    2. Run "python -m SimpleHTTPServer" or "python3 -m http.server".
    3. Point your web browser at "http://127.0.0.1:8000/foo.txt/".
    4. Note that the server has served the contents of "foo.txt" as "foo.txt/". It shouldn't do that!

    Reproduced with 2.7.3, 3.2.3, and 3.3.0. I assume it's still there in trunk.

    @larryhastings larryhastings added stdlib Python modules in the Lib dir easy type-bug An unexpected behavior, bug, or error labels Mar 1, 2013
    @orsenthil
    Copy link
    Member

    I thought this was fixed (recently). Shall look again. Having the tests is the only hard part here.

    @karlcow
    Copy link
    Mannequin

    karlcow mannequin commented Mar 6, 2013

    orsenthil,

    would that test work?
    See issue-17324-test-1.patch

    Here the result of the test which is FAIL as planned (given the current issue).

    → ./python.exe Lib/test/test_httpservers.py

    test_header_buffering_of_send_error (main.BaseHTTPRequestHandlerTestCase) ... ok
    […]

    test_get (main.SimpleHTTPServerTestCase) ... FAIL

    […]

    test_start_with_double_slash (main.SimpleHTTPRequestHandlerTestCase) ... ok

    ======================================================================
    FAIL: test_get (main.SimpleHTTPServerTestCase)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "Lib/test/test_httpservers.py", line 254, in test_get
        self.check_status_and_reason(response, 404, data=self.data)
      File "Lib/test/test_httpservers.py", line 243, in check_status_and_reason
        self.assertEqual(response.status, status)
    AssertionError: 200 != 404

    Ran 39 tests in 4.382s

    FAILED (failures=1)
    Traceback (most recent call last):
      File "Lib/test/test_httpservers.py", line 686, in <module>
        test_main()
      File "Lib/test/test_httpservers.py", line 680, in test_main
        SimpleHTTPRequestHandlerTestCase,
      File "/Users/karl/Documents/2011/cpython/Lib/test/support.py", line 1589, in run_unittest
        _run_suite(suite)
      File "/Users/karl/Documents/2011/cpython/Lib/test/support.py", line 1564, in _run_suite
        raise TestFailed(err)
    test.support.TestFailed: Traceback (most recent call last):
      File "Lib/test/test_httpservers.py", line 254, in test_get
        self.check_status_and_reason(response, 404, data=self.data)
      File "Lib/test/test_httpservers.py", line 243, in check_status_and_reason
        self.assertEqual(response.status, status)
    AssertionError: 200 != 404

    [141593 refs]

    @senko
    Copy link
    Mannequin

    senko mannequin commented Jul 6, 2013

    The attached test (issue-17324-test-1) reproduces the issue for me on 3.4.0alpha.

    @vajrasky
    Copy link
    Mannequin

    vajrasky mannequin commented Jul 8, 2013

    Attached the fix and the unit test for this problem.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 13, 2013

    New changeset a58b620e4dc9 by Senthil Kumaran in branch '2.7':
    Fix SimpleHTTPServer's request handling case on trailing '/'.
    http://hg.python.org/cpython/rev/a58b620e4dc9

    New changeset 1fcccbbe15e2 by Senthil Kumaran in branch '3.3':
    Fix http.server's request handling case on trailing '/'.
    http://hg.python.org/cpython/rev/1fcccbbe15e2

    New changeset b85c9d2a5227 by Senthil Kumaran in branch 'default':
    Fix http.server's request handling case on trailing '/'.
    http://hg.python.org/cpython/rev/b85c9d2a5227

    @orsenthil
    Copy link
    Member

    Thanks for the patches, Vajrasky and Karl. Fixed in currently active (3.4,3.3 and 2.7) versions of python.

    @orsenthil orsenthil self-assigned this Sep 13, 2013
    @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
    easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants