changeset 5326:1ba150d90d3a

custom patch for werkzeug 0.5.1 http.parse_date to catch exceptions raised by stdlib, remove exception handler at moin level
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 29 Nov 2009 16:58:27 +0100
parents e8dc5fee60d3
children 501b170e3238
files MoinMoin/action/AttachFile.py MoinMoin/support/werkzeug/http.py
diffstat 2 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Sun Nov 29 02:02:04 2009 +0100
+++ b/MoinMoin/action/AttachFile.py	Sun Nov 29 16:58:27 2009 +0100
@@ -815,16 +815,7 @@
         return # error msg already sent in _access_file
 
     timestamp = datetime.datetime.fromtimestamp(os.path.getmtime(fpath))
-    try:
-        if_modified = request.if_modified_since
-    except OverflowError:
-        # there is likely a bug somewhere in stdlib or werkzeug that triggers this
-        # we collect more data about it here and avoid moin crashing
-        logging.error("complete request.environ for exception below: %r" % request.environ)
-        logging.exception("HTTP_IF_MODIFIED_SINCE == %r caused an OverflowError" %
-                          request.environ.get('HTTP_IF_MODIFIED_SINCE'))
-        if_modified = None
-
+    if_modified = request.if_modified_since
     if if_modified and if_modified >= timestamp:
         request.status_code = 304
     else:
--- a/MoinMoin/support/werkzeug/http.py	Sun Nov 29 02:02:04 2009 +0100
+++ b/MoinMoin/support/werkzeug/http.py	Sun Nov 29 16:58:27 2009 +0100
@@ -427,7 +427,18 @@
             # if no timezone is part of the string we assume UTC
             if t[-1] is None:
                 t = t[:-1] + (0,)
-            return datetime.utcfromtimestamp(mktime_tz(t))
+            try:
+                return datetime.utcfromtimestamp(mktime_tz(t))
+            except (OverflowError, ValueError):
+                # XXX Exception handler added by MoinMoin development:
+                # catch exceptions raised by the stdlib functions if they receive far-off or invalid values.
+                # This can happen if a user agent transmits a broken if-modified-since header:
+                # 'HTTP_IF_MODIFIED_SINCE': 'Mon, 23 Jan 3115 29:41:44 GMT'
+                # 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5'
+                # TODO: remove this patch if we require a werkzeug version > 0.5.1
+                # that has an official fix for this problem.
+                # related werkzeug ticket: http://dev.pocoo.org/projects/werkzeug/ticket/432
+                return None  # just tell we can't parse this
 
 
 def default_stream_factory(total_content_length, filename, content_type,