Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #4947 -- Avoid displaying uploaded file contents in the debug w…

…eb page. Based on a patch from eibaan@gmail.com.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5874 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3757f30c99838783402b54d1cfd41958d1493aad 1 parent 78dfdd5
Malcolm Tredinnick authored August 12, 2007
1  AUTHORS
@@ -101,6 +101,7 @@ answer newbie questions, and generally made Django that much better:
101 101
     dusk@woofle.net
102 102
     Andy Dustman <farcepest@gmail.com>
103 103
     Clint Ecker
  104
+    eibaan@gmail.com
104 105
     enlight
105 106
     Enrico <rico.bl@gmail.com>
106 107
     A. Murat Eren <meren@pardus.org.tr>
6  django/http/__init__.py
@@ -2,7 +2,7 @@
2 2
 from Cookie import SimpleCookie
3 3
 from pprint import pformat
4 4
 from urllib import urlencode
5  
-from django.utils.datastructures import MultiValueDict
  5
+from django.utils.datastructures import MultiValueDict, FileDict
6 6
 from django.utils.encoding import smart_str, iri_to_uri, force_unicode
7 7
 
8 8
 RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
@@ -88,11 +88,11 @@ def parse_file_upload(header_dict, post_data):
88 88
                 # directory separator, which may not be the same as the
89 89
                 # client's one.)
90 90
                 filename = name_dict['filename'][name_dict['filename'].rfind("\\")+1:]
91  
-                FILES.appendlist(name_dict['name'], {
  91
+                FILES.appendlist(name_dict['name'], FileDict({
92 92
                     'filename': filename,
93 93
                     'content-type': 'Content-Type' in submessage and submessage['Content-Type'] or None,
94 94
                     'content': submessage.get_payload(),
95  
-                })
  95
+                }))
96 96
             else:
97 97
                 POST.appendlist(name_dict['name'], submessage.get_payload())
98 98
     return POST, FILES
13  django/utils/datastructures.py
@@ -267,3 +267,16 @@ def __init__(self, key_to_list_mapping):
267 267
                 current[bits[-1]] = v
268 268
             except TypeError: # Special-case if current isn't a dict.
269 269
                 current = {bits[-1] : v}
  270
+
  271
+class FileDict(dict):
  272
+    """
  273
+    A dictionary used to hold uploaded file contents. The only special feature
  274
+    here is that repr() of this object won't dump the entire contents of the
  275
+    file to the output. A handy safeguard for a large file upload.
  276
+    """
  277
+    def __repr__(self):
  278
+        if 'content' in self:
  279
+            d = dict(self, content='<omitted>')
  280
+            return dict.__repr__(d)
  281
+        return dict.__repr__(self)
  282
+
9  tests/regressiontests/datastructures/tests.py
@@ -64,4 +64,13 @@
64 64
 ['Holovaty']
65 65
 >>> d['person']['2']['firstname']
66 66
 ['Adrian']
  67
+
  68
+### FileDict ################################################################
  69
+
  70
+>>> d = FileDict({'content': 'once upon a time...'})
  71
+>>> repr(d)
  72
+"{'content': '<omitted>'}"
  73
+>>> d = FileDict({'other-key': 'once upon a time...'})
  74
+>>> repr(d)
  75
+"{'other-key': 'once upon a time...'}"
67 76
 """

0 notes on commit 3757f30

Please sign in to comment.
Something went wrong with that request. Please try again.