Skip to content
This repository has been archived by the owner on Jan 31, 2018. It is now read-only.

Commit

Permalink
Merge pull request #524 from lgp171188/1141410-unicode-decode-exception
Browse files Browse the repository at this point in the history
[bug 1141410]Fix unicode exception when feedback has invalid unicode URL
  • Loading branch information
willkg committed Mar 12, 2015
2 parents 135ac75 + 7fa256a commit dad6bea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
5 changes: 3 additions & 2 deletions fjord/feedback/models.py
Expand Up @@ -658,8 +658,9 @@ def validate_url(self, attrs, source):
value = attrs[source]
if value:
if not is_url(value):
raise serializers.ValidationError(
'{0} is not a valid url'.format(value))
msg = u'{0} is not a valid url'.format(value)
raise serializers.ValidationError(msg)


return attrs

Expand Down
30 changes: 29 additions & 1 deletion fjord/feedback/tests/test_api.py
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
import json
import time
from datetime import date, datetime, timedelta

from django.core.cache import get_cache
from django.test.client import Client

from nose.tools import eq_
from nose.tools import eq_, ok_

from fjord.base.tests import TestCase, reverse
from fjord.feedback import models
Expand Down Expand Up @@ -366,6 +367,33 @@ def test_maximal(self):
else:
eq_(getattr(feedback, field), data[field])

def test_invalid_unicode_url(self):
"""Tests an API call with invalid unicode URL"""
data = {
'happy': True,
'description': u'Great!',
'category': u'ui',
'product': u'Firefox OS',
'channel': u'stable',
'version': u'1.1',
'platform': u'Firefox OS',
'locale': 'en-US',
'email': 'foo@example.com',
'url': 'தமிழகம்',
'manufacturer': 'OmniCorp',
'device': 'OmniCorp',
'country': 'US',
'user_agent': (
'Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0'
),
'source': 'email',
'campaign': 'email_test',
}
r = self.client.post(reverse('feedback-api'), data)
ok_(r.rendered_content.startswith('{"url": ["'))
ok_(r.rendered_content.endswith('is not a valid url"]}'))
eq_(r.status_code, 400)

def test_with_email(self):
data = {
'happy': True,
Expand Down

0 comments on commit dad6bea

Please sign in to comment.