Skip to content

Commit

Permalink
Fix malformed error message when creating invalid Realm Emoji.
Browse files Browse the repository at this point in the history
Thanks to Greg McCoy for his help finding this bug.
  • Loading branch information
timabbott committed Jun 4, 2016
1 parent 8ad20e9 commit 03debdf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tools/lint-all
Expand Up @@ -193,7 +193,7 @@ python_rules = [
'return json_error(data=error_data, msg=ret_error)'),
('zerver/views/streams.py', 'return json_error(property_conversion)'),
# We can't do anything about this.
('zerver/views/realm_emoji.py', 'return json_error(e.message_dict)'),
('zerver/views/realm_emoji.py', 'return json_error(e.messages[0])'),
]),
'description': 'Argument to json_error should a literal string enclosed by _()'},
# To avoid JsonableError(_variable) and JsonableError(_(variable))
Expand Down
4 changes: 3 additions & 1 deletion zerver/models.py
Expand Up @@ -25,6 +25,7 @@
from zerver.lib.timestamp import datetime_to_timestamp
from django.db.models.signals import pre_save, post_save, post_delete
from django.core.validators import MinLengthValidator, RegexValidator
from django.utils.translation import ugettext as _
import zlib

from bitfield import BitField
Expand Down Expand Up @@ -243,7 +244,8 @@ class RealmEmoji(models.Model):
realm = models.ForeignKey(Realm)
# Second part of the regex (negative lookbehind) disallows names ending with one of the punctuation characters
name = models.TextField(validators=[MinLengthValidator(1),
RegexValidator(regex=r'^[0-9a-zA-Z.\-_]+(?<![.\-_])$')])
RegexValidator(regex=r'^[0-9a-zA-Z.\-_]+(?<![.\-_])$',
message=_("Invalid characters in Emoji name"))])
# URLs start having browser compatibility problem below 2000
# characters, so 1000 seems like a safe limit.
img_url = models.URLField(max_length=1000)
Expand Down
2 changes: 1 addition & 1 deletion zerver/views/realm_emoji.py
Expand Up @@ -23,7 +23,7 @@ def upload_emoji(request, user_profile):
try:
check_add_realm_emoji(user_profile.realm, emoji_name, emoji_url)
except ValidationError as e:
return json_error(e.message_dict)
return json_error(e.messages[0])
return json_success()

def delete_emoji(request, user_profile, emoji_name):
Expand Down

0 comments on commit 03debdf

Please sign in to comment.