Django

Code

Changeset 4919

Show
Ignore:
Timestamp:
04/04/07 01:43:28 (2 years ago)
Author:
mtredinnick
Message:

Made django.utils.html.escape() work with unicode strings (and unicode-like
objects). Refs #3897.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/utils/html.py

    r4885 r4919  
    22 
    33import re, string 
     4from django.utils.encoding import smart_unicode 
    45 
    56# Configuration for urlize() function 
     
    2526    "Returns the given HTML with ampersands, quotes and carets encoded" 
    2627    if not isinstance(html, basestring): 
    27         html = str(html) 
     28        html = smart_unicode(html) 
    2829    return html.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;') 
    2930 
  • django/trunk/tests/regressiontests/defaultfilters/tests.py

    r4753 r4919  
     1# -*- coding: utf-8 -*- 
     2 
    13r""" 
    24>>> floatformat(7.7) 
     
    8890'A sentence with a few words in it' 
    8991 
    90 >>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 0)  
    91 '' 
    92   
    93 >>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 2)  
     92>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 0) 
     93'' 
     94 
     95>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 2) 
    9496'<p>one <a href="#">two ...</a></p>' 
    95   
    96 >>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 4)  
     97 
     98>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 4) 
    9799'<p>one <a href="#">two - three <br>four ...</a></p>' 
    98100 
    99 >>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 5)  
     101>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 5) 
    100102'<p>one <a href="#">two - three <br>four</a> five</p>' 
    101103 
    102 >>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 100)  
     104>>> truncatewords_html('<p>one <a href="#">two - three <br>four</a> five</p>', 100) 
    103105'<p>one <a href="#">two - three <br>four</a> five</p>' 
    104106 
     
    166168>>> escape('<some html & special characters > here') 
    167169'&lt;some html &amp; special characters &gt; here' 
     170 
     171>>> escape(u'<some html & special characters > here ĐÅ€£') 
     172u'&lt;some html &amp; special characters &gt; here \xc4\x90\xc3\x85\xe2\x82\xac\xc2\xa3' 
    168173 
    169174>>> linebreaks('line 1')