Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#2909 closed defect (fixed)

Invalid utf-8 decode errors handling

Reported by: jiivan Owned by: adrian
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: UI/UX:


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

Here is quick and dirty solution:

--- core/  2006-10-13 16:39:12.000000000 +0200
+++ core/     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.maxlength = maxlength

--- core/  2006-10-13 16:40:15.000000000 +0200
+++ core/     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
         raise ValidationError, _("This value must contain only letters, numbers and underscores.")

Attachments (0)

Change History (3)

comment:1 Changed 8 years ago by anonymous

oops, patch is reverted :->

comment:2 Changed 7 years ago by Simon G. <dev@…>

  • Resolution set to fixed
  • Status changed from new to closed

Is this still an issue after the unicode branch merge?

comment:3 Changed 7 years ago by mtredinnick

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

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.