diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index cb16e4b..673d044 100644
a
|
b
|
def floatformat(text, arg=-1):
|
149 | 149 | except InvalidOperation: |
150 | 150 | if input_val in special_floats: |
151 | 151 | return input_val |
152 | | else: |
| 152 | try: |
| 153 | d = Decimal(force_unicode(float(text))) |
| 154 | except (ValueError, InvalidOperation, TypeError, UnicodeEncodeError): |
153 | 155 | return u'' |
154 | 156 | try: |
155 | 157 | p = int(arg) |
diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
index a97596f..027fcbb 100644
a
|
b
|
u'8.280'
|
35 | 35 | u'' |
36 | 36 | >>> floatformat(13.1031, u'bar') |
37 | 37 | u'13.1031' |
38 | | >>> floatformat(18.125, 2) |
39 | | u'18.13' |
| 38 | >>> floatformat(18.125, 2) |
| 39 | u'18.13' |
40 | 40 | >>> floatformat(u'foo', u'bar') |
41 | 41 | u'' |
42 | 42 | >>> floatformat(u'¿Cómo esta usted?') |
… |
… |
True
|
53 | 53 | >>> floatformat(nan) == unicode(nan) |
54 | 54 | True |
55 | 55 | |
| 56 | >>> class FloatWrapper(object): |
| 57 | ... def __init__(self, value): |
| 58 | ... self.value = value |
| 59 | ... def __float__(self): |
| 60 | ... return self.value |
| 61 | |
| 62 | >>> floatformat(FloatWrapper(11.000001), -2) |
| 63 | u'11.00' |
| 64 | |
56 | 65 | >>> addslashes(u'"double quotes" and \'single quotes\'') |
57 | 66 | u'\\"double quotes\\" and \\\'single quotes\\\'' |
58 | 67 | |
… |
… |
u'<a href="http://31characteruri.com/test/" rel="nofollow">http://31characteruri
|
180 | 189 | u'<a href="http://31characteruri.com/test/" rel="nofollow">...</a>' |
181 | 190 | |
182 | 191 | # Check normal urlize |
183 | | >>> urlize('http://google.com') |
| 192 | >>> urlize('http://google.com') |
184 | 193 | u'<a href="http://google.com" rel="nofollow">http://google.com</a>' |
185 | 194 | |
186 | | >>> urlize('http://google.com/') |
| 195 | >>> urlize('http://google.com/') |
187 | 196 | u'<a href="http://google.com/" rel="nofollow">http://google.com/</a>' |
188 | 197 | |
189 | | >>> urlize('www.google.com') |
| 198 | >>> urlize('www.google.com') |
190 | 199 | u'<a href="http://www.google.com" rel="nofollow">www.google.com</a>' |
191 | 200 | |
192 | | >>> urlize('djangoproject.org') |
| 201 | >>> urlize('djangoproject.org') |
193 | 202 | u'<a href="http://djangoproject.org" rel="nofollow">djangoproject.org</a>' |
194 | 203 | |
195 | | >>> urlize('info@djangoproject.org') |
| 204 | >>> urlize('info@djangoproject.org') |
196 | 205 | u'<a href="mailto:info@djangoproject.org">info@djangoproject.org</a>' |
197 | 206 | |
198 | 207 | # Check urlize with https addresses |
199 | | >>> urlize('https://google.com') |
| 208 | >>> urlize('https://google.com') |
200 | 209 | u'<a href="https://google.com" rel="nofollow">https://google.com</a>' |
201 | 210 | |
202 | 211 | |