Ticket #22114: 22114-1.diff

File 22114-1.diff, 6.8 KB (added by Claude Paroz, 11 years ago)
  • django/forms/fields.py

    diff --git a/django/forms/fields.py b/django/forms/fields.py
    index 8b5fd2c..93047bb 100644
    a b class URLField(CharField):  
    700700                # Rebuild the url_fields list, since the domain segment may now
    701701                # contain the path too.
    702702                url_fields = split_url(urlunsplit(url_fields))
    703             if not url_fields[2]:
     703            if url_fields[3] and not url_fields[2]:
    704704                # the path portion may need to be added before query params
    705705                url_fields[2] = '/'
    706706            value = urlunsplit(url_fields)
  • docs/releases/1.7.txt

    diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt
    index 4d1890b..5dda7ea 100644
    a b Miscellaneous  
    11031103* ``Widget.is_hidden`` is now a read-only property, getting its value by
    11041104  introspecting the presence of ``input_type == 'hidden'``.
    11051105
     1106* ``URLField.to_python`` used to always add a trailing slash to pathless URLs.
     1107  Now it only adds it if the URL contains a query part.
     1108
    11061109* :meth:`~django.db.models.query.QuerySet.select_related` now chains in the
    11071110  same way as other similar calls like ``prefetch_related``. That is,
    11081111  ``select_related('foo', 'bar')`` is equivalent to
  • tests/forms_tests/tests/test_fields.py

    diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py
    index 8cea26c..b7fd013 100644
    a b class FieldsTests(SimpleTestCase):  
    737737        self.assertWidgetRendersTo(f, '<input type="url" name="f" id="id_f" />')
    738738        self.assertRaisesMessage(ValidationError, "'This field is required.'", f.clean, '')
    739739        self.assertRaisesMessage(ValidationError, "'This field is required.'", f.clean, None)
    740         self.assertEqual('http://localhost/', f.clean('http://localhost'))
    741         self.assertEqual('http://example.com/', f.clean('http://example.com'))
    742         self.assertEqual('http://example.com./', f.clean('http://example.com.'))
    743         self.assertEqual('http://www.example.com/', f.clean('http://www.example.com'))
     740        self.assertEqual('http://localhost', f.clean('http://localhost'))
     741        self.assertEqual('http://example.com', f.clean('http://example.com'))
     742        self.assertEqual('http://example.com.', f.clean('http://example.com.'))
     743        self.assertEqual('http://www.example.com', f.clean('http://www.example.com'))
    744744        self.assertEqual('http://www.example.com:8000/test', f.clean('http://www.example.com:8000/test'))
    745         self.assertEqual('http://valid-with-hyphens.com/', f.clean('valid-with-hyphens.com'))
    746         self.assertEqual('http://subdomain.domain.com/', f.clean('subdomain.domain.com'))
    747         self.assertEqual('http://200.8.9.10/', f.clean('http://200.8.9.10'))
     745        self.assertEqual('http://valid-with-hyphens.com', f.clean('valid-with-hyphens.com'))
     746        self.assertEqual('http://subdomain.domain.com', f.clean('subdomain.domain.com'))
     747        self.assertEqual('http://200.8.9.10', f.clean('http://200.8.9.10'))
    748748        self.assertEqual('http://200.8.9.10:8000/test', f.clean('http://200.8.9.10:8000/test'))
    749749        self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'foo')
    750750        self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'http://')
    class FieldsTests(SimpleTestCase):  
    757757        self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'http://-invalid.com')
    758758        self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'http://inv-.alid-.com')
    759759        self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'http://inv-.-alid.com')
    760         self.assertEqual('http://valid-----hyphens.com/', f.clean('http://valid-----hyphens.com'))
     760        self.assertEqual('http://valid-----hyphens.com', f.clean('http://valid-----hyphens.com'))
    761761        self.assertEqual('http://some.idn.xyz\xe4\xf6\xfc\xdfabc.domain.com:123/blah', f.clean('http://some.idn.xyzäöüßabc.domain.com:123/blah'))
    762762        self.assertEqual('http://www.example.com/s/http://code.djangoproject.com/ticket/13804', f.clean('www.example.com/s/http://code.djangoproject.com/ticket/13804'))
    763763        self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, '[a')
    class FieldsTests(SimpleTestCase):  
    776776        f = URLField(required=False)
    777777        self.assertEqual('', f.clean(''))
    778778        self.assertEqual('', f.clean(None))
    779         self.assertEqual('http://example.com/', f.clean('http://example.com'))
    780         self.assertEqual('http://www.example.com/', f.clean('http://www.example.com'))
     779        self.assertEqual('http://example.com', f.clean('http://example.com'))
     780        self.assertEqual('http://www.example.com', f.clean('http://www.example.com'))
    781781        self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'foo')
    782782        self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'http://')
    783783        self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'http://example')
    class FieldsTests(SimpleTestCase):  
    787787    def test_urlfield_5(self):
    788788        f = URLField(min_length=15, max_length=20)
    789789        self.assertWidgetRendersTo(f, '<input id="id_f" type="url" name="f" maxlength="20" />')
    790         self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 15 characters (it has 13).'", f.clean, 'http://f.com')
    791         self.assertEqual('http://example.com/', f.clean('http://example.com'))
    792         self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 38).'", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
     790        self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 15 characters (it has 12).'", f.clean, 'http://f.com')
     791        self.assertEqual('http://example.com', f.clean('http://example.com'))
     792        self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 37).'", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
    793793
    794794    def test_urlfield_6(self):
    795795        f = URLField(required=False)
    796         self.assertEqual('http://example.com/', f.clean('example.com'))
     796        self.assertEqual('http://example.com', f.clean('example.com'))
    797797        self.assertEqual('', f.clean(''))
    798         self.assertEqual('https://example.com/', f.clean('https://example.com'))
     798        self.assertEqual('https://example.com', f.clean('https://example.com'))
    799799
    800800    def test_urlfield_7(self):
    801801        f = URLField()
    802         self.assertEqual('http://example.com/', f.clean('http://example.com'))
     802        self.assertEqual('http://example.com', f.clean('http://example.com'))
    803803        self.assertEqual('http://example.com/test', f.clean('http://example.com/test'))
    804804
    805805    def test_urlfield_8(self):
Back to Top