summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-02-19 17:27:53 -0300
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-02-19 17:27:53 -0300
commit8f5dd762fce09a4eb72bf58ad3b9a9a596000575 (patch)
treef27fe4e0bfe92c57ff676a48274ce225d13132c6
parent461496e5cf1bf23927948e498e1ae6c5f9379a0a (diff)
downloadaskbot-8f5dd762fce09a4eb72bf58ad3b9a9a596000575.tar.gz
askbot-8f5dd762fce09a4eb72bf58ad3b9a9a596000575.tar.bz2
askbot-8f5dd762fce09a4eb72bf58ad3b9a9a596000575.zip
added validation of maximum length of title, which works for utf-8 input
-rw-r--r--askbot/doc/source/changelog.rst1
-rw-r--r--askbot/forms.py16
2 files changed, 17 insertions, 0 deletions
diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst
index 965db53c..54baa18f 100644
--- a/askbot/doc/source/changelog.rst
+++ b/askbot/doc/source/changelog.rst
@@ -17,6 +17,7 @@ Development version (not released yet)
* Added a management command to build_thread_summary_cache (Evgeny)
* Added a management delete_contextless_badge_award_activities (Evgeny)
* Fixed a file upload issue in FF and IE found by jerry_gzy (Evgeny)
+* Added test on maximum length of title working for utf-8 text (Evgeny)
0.7.39 (Jan 11, 2012)
---------------------
diff --git a/askbot/forms.py b/askbot/forms.py
index 08645fcd..fcf43814 100644
--- a/askbot/forms.py
+++ b/askbot/forms.py
@@ -113,6 +113,22 @@ class TitleField(forms.CharField):
askbot_settings.MIN_TITLE_LENGTH
) % askbot_settings.MIN_TITLE_LENGTH
raise forms.ValidationError(msg)
+ encoded_value = value.encode('utf-8')
+ if len(value) == len(encoded_value):
+ if len(value) > self.max_length:
+ raise forms.ValidationError(
+ _(
+ 'The title is too long, maximum allowed size is '
+ '%d characters'
+ ) % self.max_length
+ )
+ elif encoded_value > self.max_length:
+ raise forms.ValidationError(
+ _(
+ 'The title is too long, maximum allowed size is '
+ '%d bytes'
+ ) % self.max_length
+ )
return value.strip() # TODO: test me