[Django] #32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on Windows

6 views
Skip to first unread message

Django

unread,
Mar 17, 2021, 7:48:09 PM3/17/21
to django-...@googlegroups.com
#32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
Reporter: timoguic | Owner: nobody
Type: | Status: new
Uncategorized |
Component: Testing | Version: 3.1
framework | Keywords: windows,
Severity: Normal | liveservertestcase, path
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I am using Python 3.8 32-bit on Windows: Python 3.8.5
(tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)]
on win32

I installed Django and requests in a virtual environment:
pip install django requests

My virtual environment now has:
{{{
asgiref==3.3.1
certifi==2020.12.5
chardet==4.0.0
Django==3.1.7
idna==2.10
pytz==2021.1
requests==2.25.1
sqlparse==0.4.1
urllib3==1.26.4
}}}

I created a new Django project:
{{{
django-admin.exe startproject example
cd example
django-admin.exe startapp livecase
}}}

I used the following code in my example/livecase/views.py:
{{{
from django.http import HttpResponse

def example(request):
return HttpResponse("OK")
}}}

And the following in example/example/urls.py:
{{{
from django.contrib import admin
from django.urls import path
from livecase.views import example

urlpatterns = [
path('test:12345/', example),
path('admin/', admin.site.urls),
]
}}}

I then used the following code in example/livecase/tests.py:
{{{
from django.test import LiveServerTestCase
import requests

class MyTest(LiveServerTestCase):
def test_example(self):
r = requests.get(f"{self.live_server_url}/test:12345/")
self.assertEqual(r.status_code, 200)
}}}

I run the tests: python manage.py test

I get the following error, with the traceback:
{{{
Traceback (most recent call last):
File
"C:\[redacted]\AppData\Local\Programs\Python\Python38-32\lib\wsgiref\handlers.py",
line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\[redacted]\venv-test\lib\site-
packages\django\test\testcases.py", line 1324, in __call__
return self.application(environ, start_response)
File "C:\[redacted]\venv-test\lib\site-
packages\django\test\testcases.py", line 1325, in __call__
return super().__call__(environ, start_response)
File "C:\[redacted]\venv-test\lib\site-
packages\django\core\handlers\wsgi.py", line 133, in __call__
response = self.get_response(request)
File "C:\[redacted]\venv-test\lib\site-
packages\django\test\testcases.py", line 1305, in get_response
return self.serve(request)
File "C:\[redacted]\venv-test\lib\site-
packages\django\test\testcases.py", line 1320, in serve
return serve(request, final_rel_path,
document_root=self.get_base_dir())
File "C:\[redacted]\venv-test\lib\site-packages\django\views\static.py",
line 38, in serve
fullpath = Path(safe_join(document_root, path))
File "C:\[redacted]\venv-test\lib\site-packages\django\utils\_os.py",
line 29, in safe_join
raise SuspiciousFileOperation(
django.core.exceptions.SuspiciousFileOperation: The joined path (T:\12345)
is located outside of the base path component (C:\[redacted]\example)
F
======================================================================
FAIL: test_example (livecase.tests.MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\[redacted]\example\livecase\tests.py", line 9, in test_example
self.assertEqual(r.status_code, 200)
AssertionError: 500 != 200

----------------------------------------------------------------------
Ran 1 test in 0.528s
}}}

If I use "|" instead of ":" in the URL in the test case, the same problem
happens.
If I use self.client.get, the test passes and no exception is raised.

I tried to replicate the issue in a Linux environment, and I was not able
to (although using Python 3.8 64 bit).

I believe the path conversion issue is happening at
https://github.com/django/django/blob/45814af6197cfd8f4dc72ee43b90ecde305a1d5a/django/test/testcases.py#L1439

Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/32567>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 17, 2021, 9:39:08 PM3/17/21
to django-...@googlegroups.com
#32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
Reporter: Tim G | Owner: nobody
Type: Uncategorized | Status: new
Component: Testing framework | Version: 3.1
Severity: Normal | Resolution:
Keywords: windows, | Triage Stage:
liveservertestcase, path | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim G):

To illustrate the problem better, I added one (failing) test in the test
suite:

https://github.com/timoguic/django/commits/ticket_32567/tests/staticfiles_tests/test_liveserver.py

--
Ticket URL: <https://code.djangoproject.com/ticket/32567#comment:1>

Django

unread,
Mar 18, 2021, 1:39:10 AM3/18/21
to django-...@googlegroups.com
#32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
Reporter: Tim G | Owner: nobody
Type: Uncategorized | Status: new
Component: Testing framework | Version: 3.1
Severity: Normal | Resolution:
Keywords: windows, | Triage Stage:
liveservertestcase, path | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Tim G:

Old description:

New description:

https://github.com/django/django/blob/45814af6197cfd8f4dc72ee43b90ecde305a1d5a/django/test/testcases.py#L1438

Thanks.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32567#comment:2>

Django

unread,
Mar 18, 2021, 9:41:35 AM3/18/21
to django-...@googlegroups.com
#32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
Reporter: Tim G | Owner: nobody
Type: Uncategorized | Status: new
Component: Testing framework | Version: 3.1
Severity: Normal | Resolution:
Keywords: windows, | Triage Stage:
liveservertestcase, path | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

Hey Tim, nice report thanks.

I didn't have the time to assess yet, but a couple of questions:

1. Did you example `request.path` there — what's it look like? What about
`request.META`?
2. Does it happen with `runserver` hitting the URL by hand?

--
Ticket URL: <https://code.djangoproject.com/ticket/32567#comment:3>

Django

unread,
Mar 18, 2021, 11:00:35 AM3/18/21
to django-...@googlegroups.com
#32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
Reporter: Tim G | Owner: nobody
Type: Uncategorized | Status: new
Component: Testing framework | Version: 3.1
Severity: Normal | Resolution:
Keywords: windows, | Triage Stage: Accepted
liveservertestcase, path |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Unreviewed => Accepted


Comment:

Reproduced on Windows 10 (64bit) with the test case provided.

Tim do you fancy opening a PR with the test at least, so that it's easier
to work with?

Thanks again for the report. Really very clear.

--
Ticket URL: <https://code.djangoproject.com/ticket/32567#comment:4>

Django

unread,
Mar 18, 2021, 11:42:34 AM3/18/21
to django-...@googlegroups.com
#32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
Reporter: Tim G | Owner: nobody
Type: Uncategorized | Status: new
Component: Testing framework | Version: 3.1
Severity: Normal | Resolution:
Keywords: windows, | Triage Stage: Accepted
liveservertestcase, path |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim G):

Replying to [comment:4 Carlton Gibson]:


> Tim do you fancy opening a PR with the test at least, so that it's
easier to work with?

Sure. I just did that.

I think I found a fix, but I am not sure if it's the right approach. Shall
I commit in the PR still?

--
Ticket URL: <https://code.djangoproject.com/ticket/32567#comment:5>

Django

unread,
Mar 18, 2021, 3:51:02 PM3/18/21
to django-...@googlegroups.com
#32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
Reporter: Tim G | Owner: nobody
Type: Uncategorized | Status: new
Component: Testing framework | Version: 3.1
Severity: Normal | Resolution:
Keywords: windows, | Triage Stage: Accepted
liveservertestcase, path |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

Hey Tim. Yes, do. It’ll highlight what’s going on. We can assess it in
review.
Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/32567#comment:6>

Django

unread,
Mar 18, 2021, 3:59:18 PM3/18/21
to django-...@googlegroups.com
#32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
Reporter: Tim G | Owner: nobody
Type: Uncategorized | Status: new
Component: Testing framework | Version: 3.1
Severity: Normal | Resolution:
Keywords: windows, | Triage Stage: Accepted
liveservertestcase, path |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim G):

WIP is at https://github.com/django/django/pull/14146

--
Ticket URL: <https://code.djangoproject.com/ticket/32567#comment:7>

Django

unread,
Mar 30, 2021, 2:24:30 PM3/30/21
to django-...@googlegroups.com
#32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
Reporter: Tim G | Owner: nobody
Type: Bug | Status: new

Component: Testing framework | Version: 3.1
Severity: Normal | Resolution:
Keywords: windows, | Triage Stage: Accepted
liveservertestcase, path |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/32567#comment:8>

Django

unread,
Jul 5, 2021, 12:40:06 AM7/5/21
to django-...@googlegroups.com
#32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
Reporter: Tim G | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 3.1
Severity: Normal | Resolution:
Keywords: windows, | Triage Stage: Accepted
liveservertestcase, path |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32567#comment:9>

Django

unread,
Jul 5, 2021, 1:18:20 AM7/5/21
to django-...@googlegroups.com
#32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
Reporter: Tim G | Owner: Tim G
Type: Bug | Status: assigned

Component: Testing framework | Version: 3.1
Severity: Normal | Resolution:
Keywords: windows, | Triage Stage: Accepted
liveservertestcase, path |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Tim G
* needs_better_patch: 0 => 1
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/32567#comment:10>

Django

unread,
Dec 17, 2024, 5:07:30 PM12/17/24
to django-...@googlegroups.com
#32567: Issues with ":" and "|" characters in URLs when using LiveServerTestCase on
Windows
-------------------------------------+-------------------------------------
Reporter: Tim G | Owner: Tim G
Type: Bug | Status: assigned
Component: Testing framework | Version: 3.1
Severity: Normal | Resolution:
Keywords: windows, | Triage Stage: Accepted
liveservertestcase, path |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* cc: Antoliny (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/32567#comment:11>
Reply all
Reply to author
Forward
0 new messages