Opened 18 years ago

Closed 17 years ago

Last modified 17 years ago

#2909 closed defect (fixed)

Invalid utf-8 decode errors handling

Reported by: jiivan Owned by: Adrian Holovaty
Component: Validators Version: 0.91
Severity: critical Keywords: utf-8
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

when user submits invalid utf-8 string for example \xe4 basic validators are throwing exceptions.

Here is quick and dirty solution:

--- core/formfields.py  2006-10-13 16:39:12.000000000 +0200
+++ core/formfields.py.orig     2006-10-13 14:53:00.000000000 +0200
@@ -329,7 +329,7 @@
         self.field_name = field_name
         self.length, self.maxlength = length, maxlength
         self.is_required = is_required
-        self.validator_list = [validators.isValidUTF8, self.hasNoNewlines, self.isValidLength] + validator_list
+        self.validator_list = [self.isValidLength, self.hasNoNewlines] + validator_list
         if member_name != None:
             self.member_name = member_name

@@ -365,7 +365,7 @@
     def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=[], maxlength=None):
         self.field_name = field_name
         self.rows, self.cols, self.is_required = rows, cols, is_required
-        self.validator_list = [validators.isValidUTF8] + validator_list
+        self.validator_list = validator_list[:]
         if maxlength:
             self.validator_list.append(self.isValidLength)
             self.maxlength = maxlength

--- core/validators.py  2006-10-13 16:40:15.000000000 +0200
+++ core/validators.py.orig     2006-10-13 14:52:47.000000000 +0200
@@ -56,12 +56,6 @@
     def __str__(self):
         return str(self.messages)

-def isValidUTF8(field_data, all_data):
-    try:
-        field_data.decode('utf-8')
-    except UnicodeDecodeError, e:
-        raise CriticalValidationError("Błąd kodowania UTF-8: %s, przy znakach %d-%d" % (e.reason, e.start, e.end))
-
 def isAlphaNumeric(field_data, all_data):
     if not alnum_re.search(field_data):
         raise ValidationError, _("This value must contain only letters, numbers and underscores.")

Change History (3)

comment:1 by anonymous, 18 years ago

oops, patch is reverted :->

comment:2 by Simon G. <dev@…>, 17 years ago

Resolution: fixed
Status: newclosed

Is this still an issue after the unicode branch merge?

comment:3 by Malcolm Tredinnick, 17 years ago

I agree, Simon. This will have been fixed as part of the encoding/decoding work in django.http.QueryDict. Invalid input is handled there.

Note: See TracTickets for help on using tickets.
Back to Top