mirror of
				https://github.com/django/django.git
				synced 2025-11-04 05:35:37 +00:00 
			
		
		
		
	Fixed #23593 -- Fixed crash in AdminEmailHandler with non-ASCII characters in request.
Thanks edevil for the report and Simon Charette for review.
This commit is contained in:
		
							parent
							
								
									6f6e7d01dc
								
							
						
					
					
						commit
						9dff5ce7c7
					
				
					 3 changed files with 28 additions and 1 deletions
				
			
		| 
						 | 
					@ -1,3 +1,5 @@
 | 
				
			||||||
 | 
					from __future__ import unicode_literals
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import warnings
 | 
					import warnings
 | 
				
			||||||
| 
						 | 
					@ -6,6 +8,7 @@ from django.conf import settings
 | 
				
			||||||
from django.core import mail
 | 
					from django.core import mail
 | 
				
			||||||
from django.core.mail import get_connection
 | 
					from django.core.mail import get_connection
 | 
				
			||||||
from django.utils.deprecation import RemovedInNextVersionWarning
 | 
					from django.utils.deprecation import RemovedInNextVersionWarning
 | 
				
			||||||
 | 
					from django.utils.encoding import force_text
 | 
				
			||||||
from django.utils.module_loading import import_string
 | 
					from django.utils.module_loading import import_string
 | 
				
			||||||
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
 | 
					from django.views.debug import ExceptionReporter, get_exception_reporter_filter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -106,7 +109,7 @@ class AdminEmailHandler(logging.Handler):
 | 
				
			||||||
                record.getMessage()
 | 
					                record.getMessage()
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            filter = get_exception_reporter_filter(request)
 | 
					            filter = get_exception_reporter_filter(request)
 | 
				
			||||||
            request_repr = '\n{0}'.format(filter.get_request_repr(request))
 | 
					            request_repr = '\n{0}'.format(force_text(filter.get_request_repr(request)))
 | 
				
			||||||
        except Exception:
 | 
					        except Exception:
 | 
				
			||||||
            subject = '%s: %s' % (
 | 
					            subject = '%s: %s' % (
 | 
				
			||||||
                record.levelname,
 | 
					                record.levelname,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -97,3 +97,6 @@ Bugfixes
 | 
				
			||||||
  possible to import arbitrary packages from the Python path. This was not
 | 
					  possible to import arbitrary packages from the Python path. This was not
 | 
				
			||||||
  considered a security issue because ``admindocs`` is only accessible to staff
 | 
					  considered a security issue because ``admindocs`` is only accessible to staff
 | 
				
			||||||
  users (:ticket:`23601`).
 | 
					  users (:ticket:`23601`).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Fixed ``UnicodeDecodeError`` crash in ``AdminEmailHandler`` with non-ASCII
 | 
				
			||||||
 | 
					  characters in the request (:ticket:`23593`).
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
 | 
					# -*- coding:utf-8 -*-
 | 
				
			||||||
from __future__ import unicode_literals
 | 
					from __future__ import unicode_literals
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
| 
						 | 
					@ -320,6 +321,26 @@ class AdminEmailHandlerTest(TestCase):
 | 
				
			||||||
            mail.mail_admins = orig_mail_admins
 | 
					            mail.mail_admins = orig_mail_admins
 | 
				
			||||||
            admin_email_handler.email_backend = orig_email_backend
 | 
					            admin_email_handler.email_backend = orig_email_backend
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @override_settings(
 | 
				
			||||||
 | 
					        ADMINS=(('whatever admin', 'admin@example.com'),),
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    def test_emit_non_ascii(self):
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        #23593 - AdminEmailHandler should allow Unicode characters in the
 | 
				
			||||||
 | 
					        request.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        handler = self.get_admin_email_handler(self.logger)
 | 
				
			||||||
 | 
					        record = self.logger.makeRecord('name', logging.ERROR, 'function', 'lno', 'message', None, None)
 | 
				
			||||||
 | 
					        rf = RequestFactory()
 | 
				
			||||||
 | 
					        url_path = '/º'
 | 
				
			||||||
 | 
					        record.request = rf.get(url_path)
 | 
				
			||||||
 | 
					        handler.emit(record)
 | 
				
			||||||
 | 
					        self.assertEqual(len(mail.outbox), 1)
 | 
				
			||||||
 | 
					        msg = mail.outbox[0]
 | 
				
			||||||
 | 
					        self.assertEqual(msg.to, ['admin@example.com'])
 | 
				
			||||||
 | 
					        self.assertEqual(msg.subject, "[Django] ERROR (EXTERNAL IP): message")
 | 
				
			||||||
 | 
					        self.assertIn("path:%s" % url_path, msg.body)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SettingsConfigTest(AdminScriptTestCase):
 | 
					class SettingsConfigTest(AdminScriptTestCase):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue