mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #24681 -- Removed Unicode bug in BrokenLinkEmailMiddleware
This commit is contained in:
		
				
					committed by
					
						 Claude Paroz
						Claude Paroz
					
				
			
			
				
	
			
			
			
						parent
						
							6e8cb75e3e
						
					
				
				
					commit
					4cd727095d
				
			| @@ -127,7 +127,7 @@ class BrokenLinkEmailsMiddleware(object): | ||||
|             referer = force_text(request.META.get('HTTP_REFERER', ''), errors='replace') | ||||
|  | ||||
|             if not self.is_ignorable_request(request, path, domain, referer): | ||||
|                 ua = request.META.get('HTTP_USER_AGENT', '<none>') | ||||
|                 ua = force_text(request.META.get('HTTP_USER_AGENT', '<none>'), errors='replace') | ||||
|                 ip = request.META.get('REMOTE_ADDR', '<none>') | ||||
|                 mail_managers( | ||||
|                     "Broken %slink on %s" % ( | ||||
|   | ||||
| @@ -320,6 +320,16 @@ class BrokenLinkEmailsMiddlewareTest(TestCase): | ||||
|         BrokenLinkEmailsMiddleware().process_response(self.req, self.resp) | ||||
|         self.assertEqual(len(mail.outbox), 1) | ||||
|  | ||||
|     @skipIf(six.PY3, "HTTP_USER_AGENT is str type on Python 3") | ||||
|     def test_404_error_nonascii_user_agent(self): | ||||
|         # Such user agent strings should not happen, but anyway, if it happens, | ||||
|         # let's not crash | ||||
|         self.req.META['HTTP_REFERER'] = '/another/url/' | ||||
|         self.req.META['HTTP_USER_AGENT'] = b'\xd0\xbb\xd0\xb8\xff\xff' | ||||
|         BrokenLinkEmailsMiddleware().process_response(self.req, self.resp) | ||||
|         self.assertEqual(len(mail.outbox), 1) | ||||
|         self.assertIn('User agent: \u043b\u0438\ufffd\ufffd\n', mail.outbox[0].body) | ||||
|  | ||||
|     def test_custom_request_checker(self): | ||||
|         class SubclassedMiddleware(BrokenLinkEmailsMiddleware): | ||||
|             ignored_user_agent_patterns = (re.compile(r'Spider.*'), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user