Ticket #29143: NegativeIntConverter.patch

File NegativeIntConverter.patch, 1.7 KB (added by Ashish Nitin Patil, 7 years ago)
  • AUTHORS

    diff --git a/AUTHORS b/AUTHORS
    index fb32b97..8af7ffb 100644
    a b answer newbie questions, and generally made Django that much better:  
    8383    Arvis Bickovskis <viestards.lists@gmail.com>
    8484    Aryeh Leib Taurog <http://www.aryehleib.com/>
    8585    A S Alam <aalam@users.sf.net>
     86    Ashish Nitin Patil <ashishnitinpatil@gmail.com>
    8687    Asif Saif Uddin <auvipy@gmail.com>
    8788    atlithorn <atlithorn@gmail.com>
    8889    Audrey Roy <http://audreymroy.com/>
  • django/urls/converters.py

    diff --git a/django/urls/converters.py b/django/urls/converters.py
    index cc22f33..9172dc9 100644
    a b from django.utils import lru_cache  
    44
    55
    66class IntConverter:
    7     regex = '[0-9]+'
     7    regex = '-?[0-9]+'
    88
    99    def to_python(self, value):
    1010        return int(value)
  • tests/urlpatterns/tests.py

    diff --git a/tests/urlpatterns/tests.py b/tests/urlpatterns/tests.py
    index b200aed..83c5f07 100644
    a b class ConverterTests(SimpleTestCase):  
    7777            return x
    7878
    7979        test_data = (
    80             ('int', {'0', '1', '01', 1234567890}, int),
     80            ('int', {'0', '1', '01', 1234567890, '-1', '-01', -1}, int),
    8181            ('str', {'abcxyz'}, no_converter),
    8282            ('path', {'allows.ANY*characters'}, no_converter),
    8383            ('slug', {'abcxyz-ABCXYZ_01234567890'}, no_converter),
    class ConverterTests(SimpleTestCase):  
    103103
    104104    def test_nonmatching_urls(self):
    105105        test_data = (
    106             ('int', {'-1', 'letters'}),
     106            ('int', {'letters', '123mixed'}),
    107107            ('str', {'', '/'}),
    108108            ('path', {''}),
    109109            ('slug', {'', 'stars*notallowed'}),
Back to Top