From 74670498e902a0506e667cd21084c5e2eb71edfa Mon Sep 17 00:00:00 2001 From: harikrishnakanchi Date: Fri, 22 Jan 2016 00:53:51 +0530 Subject: Fixed #25971 -- Made BrokenLinkEmailsMiddleware ignore APPEND_SLASH redirects. If APPEND_SLASH=True and the referer is the URL without a trailing '/', then BrokenLinkEmailsMiddleware shouldn't send an email. --- django/middleware/common.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'django') diff --git a/django/middleware/common.py b/django/middleware/common.py index 948b76c71b..70d8c57f7e 100644 --- a/django/middleware/common.py +++ b/django/middleware/common.py @@ -162,18 +162,24 @@ class BrokenLinkEmailsMiddleware(object): def is_ignorable_request(self, request, uri, domain, referer): """ Return True if the given request *shouldn't* notify the site managers - according to project settings or in three specific situations: - - If the referer is empty. - - If a '?' in referer is identified as a search engine source. - - If the referer is equal to the current URL, ignoring the scheme - (assumed to be a poorly implemented bot). + according to project settings or in situations outlined by the inline + comments. """ + # The referer is empty. if not referer: return True + # APPEND_SLASH is enabled and the referer is equal to the current URL + # without a trailing slash indicating an internal redirect. + if settings.APPEND_SLASH and uri.endswith('/') and referer == uri[:-1]: + return True + + # A '?' in referer is identified as a search engine source. if not self.is_internal_request(domain, referer) and '?' in referer: return True + # The referer is equal to the current URL, ignoring the scheme (assumed + # to be a poorly implemented bot). parsed_referer = urlparse(referer) if parsed_referer.netloc in ['', domain] and parsed_referer.path == uri: return True -- cgit v1.3