diff --git a/django/utils/http.py b/django/utils/http.py
index 15fac6b..9897df4 100644
a
|
b
|
def same_origin(url1, url2):
|
226 | 226 | Checks if two URLs are 'same-origin' |
227 | 227 | """ |
228 | 228 | p1, p2 = urllib_parse.urlparse(url1), urllib_parse.urlparse(url2) |
229 | | return (p1.scheme, p1.hostname, p1.port) == (p2.scheme, p2.hostname, p2.port) |
| 229 | try: |
| 230 | return (p1.scheme, p1.hostname, p1.port) == (p2.scheme, p2.hostname, p2.port) |
| 231 | except ValueError: |
| 232 | return False |
230 | 233 | |
231 | 234 | def is_safe_url(url, host=None): |
232 | 235 | """ |
diff --git a/tests/csrf_tests/tests.py b/tests/csrf_tests/tests.py
index 5300b21..b9e8cb5 100644
a
|
b
|
class CsrfViewMiddlewareTest(TestCase):
|
284 | 284 | self.assertEqual(403, req2.status_code) |
285 | 285 | |
286 | 286 | @override_settings(ALLOWED_HOSTS=['www.example.com']) |
| 287 | def test_https_malformed_referer(self): |
| 288 | """ |
| 289 | Test that a POST HTTPS request with a bad referer is rejected |
| 290 | """ |
| 291 | req = self._get_POST_request_with_token() |
| 292 | req._is_secure_override = True |
| 293 | req.META['HTTP_HOST'] = 'www.example.com' |
| 294 | req.META['HTTP_REFERER'] = 'http://http://www.example.com/' |
| 295 | req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {}) |
| 296 | self.assertNotEqual(None, req2) |
| 297 | self.assertEqual(403, req2.status_code) |
| 298 | |
| 299 | @override_settings(ALLOWED_HOSTS=['www.example.com']) |
287 | 300 | def test_https_good_referer(self): |
288 | 301 | """ |
289 | 302 | Test that a POST HTTPS request with a good referer is accepted |