Opened 19 years ago
Last modified 17 years ago
#1355 closed enhancement
Internationalisation(charset) problems with FileField file names and core.db.backend.mysql — at Initial Version
Reported by: | little | Owned by: | hugo |
---|---|---|---|
Component: | Core (Other) | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
- The function django.utils.text.get_valid_filename() is not friendly for non-latin file-names
s = s.strip().replace(' ', '_') return re.sub(r'[^-A-Za-z0-9_.]', '', s)
truncates file name to underscores only: "__________.txt"
for example.
Let it retun a Unicode object of string s
return unicode(s,'utf8')
Or make it possible to overload this function to end-programmer.
- In django.core.db.backends.mysql.DatabaseWrapper in method cursor()
When you doing
self.connection = Database.connect(**kwargs) cursor = self.connection.cursor() if self.connection.get_server_info() >= '4.1': cursor.execute("SET NAMES 'utf8'")
After 'set names ..' the charset of connection was changed.
But self.connection.charset property (property of MySQLdb.connection) was not changed. It is always 'Latin1'
So, when i pass u"unicode national characters" into database, MySQLdb tryed to convert it into Latin1 and exception raises
To fix it, i must set .charset propery manually:
... self.connection = Database.connect(**kwargs) self.connection.charset = 'utf8' cursor = self.connection.cursor() if self.connection.get_server_info() >= '4.1': cursor.execute("SET NAMES 'utf8'") ...