Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
998c9dd5
Kaydet (Commit)
998c9dd5
authored
Kas 07, 2017
tarafından
Chris Lamb
Kaydeden (comit)
Tim Graham
Kas 07, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28663 -- Add a check for likely incorrectly migrated django.urls.path() routes.
üst
a4f9ef4f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
58 additions
and
2 deletions
+58
-2
resolvers.py
django/urls/resolvers.py
+10
-1
checks.txt
docs/ref/checks.txt
+3
-1
test_urls.py
tests/check_framework/test_urls.py
+30
-0
__init__.py
tests/check_framework/urls/path_compatibility/__init__.py
+0
-0
beginning_with_caret.py
...framework/urls/path_compatibility/beginning_with_caret.py
+5
-0
contains_re_named_group.py
...mework/urls/path_compatibility/contains_re_named_group.py
+5
-0
ending_with_dollar.py
...k_framework/urls/path_compatibility/ending_with_dollar.py
+5
-0
No files found.
django/urls/resolvers.py
Dosyayı görüntüle @
998c9dd5
...
...
@@ -255,7 +255,16 @@ class RoutePattern(CheckURLMixin):
return
None
def
check
(
self
):
return
self
.
_check_pattern_startswith_slash
()
warnings
=
self
.
_check_pattern_startswith_slash
()
route
=
self
.
_route
if
'(?P<'
in
route
or
route
.
startswith
(
'^'
)
or
route
.
endswith
(
'$'
):
warnings
.
append
(
Warning
(
"Your URL pattern {} has a route that contains '(?P<', begins "
"with a '^', or ends with a '$'. This was likely an oversight "
"when migrating to django.urls.path()."
.
format
(
self
.
describe
()),
id
=
'2_0.W001'
,
))
return
warnings
def
_compile
(
self
,
route
):
return
re
.
compile
(
_route_to_regex
(
route
,
self
.
_is_endpoint
)[
0
])
...
...
docs/ref/checks.txt
Dosyayı görüntüle @
998c9dd5
...
...
@@ -98,7 +98,9 @@ Backwards compatibility
Compatibility checks warn of potential problems that might occur after
upgrading Django.
Currently, there aren't any of these checks.
* **2_0.W001**: Your URL pattern ``<pattern>`` has a ``route`` that contains
``(?P<``, begins with a ``^``, or ends with a ``$``. This was likely an
oversight when migrating from ``url()`` to :func:`~django.urls.path`.
Caches
------
...
...
tests/check_framework/test_urls.py
Dosyayı görüntüle @
998c9dd5
...
...
@@ -135,6 +135,36 @@ class CheckUrlConfigTests(SimpleTestCase):
self
.
assertEqual
(
result
,
[])
class
UpdatedToPathTests
(
SimpleTestCase
):
@override_settings
(
ROOT_URLCONF
=
'check_framework.urls.path_compatibility.contains_re_named_group'
)
def
test_contains_re_named_group
(
self
):
result
=
check_url_config
(
None
)
self
.
assertEqual
(
len
(
result
),
1
)
warning
=
result
[
0
]
self
.
assertEqual
(
warning
.
id
,
'2_0.W001'
)
expected_msg
=
"Your URL pattern '(?P<named-group>
\\
d+)' has a route"
self
.
assertIn
(
expected_msg
,
warning
.
msg
)
@override_settings
(
ROOT_URLCONF
=
'check_framework.urls.path_compatibility.beginning_with_caret'
)
def
test_beginning_with_caret
(
self
):
result
=
check_url_config
(
None
)
self
.
assertEqual
(
len
(
result
),
1
)
warning
=
result
[
0
]
self
.
assertEqual
(
warning
.
id
,
'2_0.W001'
)
expected_msg
=
"Your URL pattern '^beginning-with-caret' has a route"
self
.
assertIn
(
expected_msg
,
warning
.
msg
)
@override_settings
(
ROOT_URLCONF
=
'check_framework.urls.path_compatibility.ending_with_dollar'
)
def
test_ending_with_dollar
(
self
):
result
=
check_url_config
(
None
)
self
.
assertEqual
(
len
(
result
),
1
)
warning
=
result
[
0
]
self
.
assertEqual
(
warning
.
id
,
'2_0.W001'
)
expected_msg
=
"Your URL pattern 'ending-with-dollar$' has a route"
self
.
assertIn
(
expected_msg
,
warning
.
msg
)
class
CheckURLSettingsTests
(
SimpleTestCase
):
@override_settings
(
STATIC_URL
=
'a/'
,
MEDIA_URL
=
'b/'
)
...
...
tests/check_framework/urls/path_compatibility/__init__.py
0 → 100644
Dosyayı görüntüle @
998c9dd5
tests/check_framework/urls/path_compatibility/beginning_with_caret.py
0 → 100644
Dosyayı görüntüle @
998c9dd5
from
django.urls
import
path
urlpatterns
=
[
path
(
'^beginning-with-caret'
,
lambda
x
:
x
),
]
tests/check_framework/urls/path_compatibility/contains_re_named_group.py
0 → 100644
Dosyayı görüntüle @
998c9dd5
from
django.urls
import
path
urlpatterns
=
[
path
(
'(?P<named-group>
\
d+)'
,
lambda
x
:
x
),
]
tests/check_framework/urls/path_compatibility/ending_with_dollar.py
0 → 100644
Dosyayı görüntüle @
998c9dd5
from
django.urls
import
path
urlpatterns
=
[
path
(
'ending-with-dollar$'
,
lambda
x
:
x
),
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment