Ticket #19237: 19237-parser-4.diff

File 19237-parser-4.diff, 1.7 KB (added by Claude Paroz, 11 years ago)
  • django/utils/html.py

    diff --git a/django/utils/html.py b/django/utils/html.py
    index 5732350..ebf97f8 100644
    a b def strip_tags(value):  
    137137    """Returns the given HTML with all tags stripped."""
    138138    s = MLStripper()
    139139    s.feed(value)
    140     data = s.get_data()
    141     try:
    142         res = s.close()
    143     except Exception as e:
    144         data += s.rawdata
    145     return data
     140    return s.get_data()
    146141strip_tags = allow_lazy(strip_tags)
    147142
    148143def remove_tags(html, tags):
  • docs/ref/utils.txt

    diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt
    index 14ae9aa..9f8b1f1 100644
    a b escaping HTML.  
    566566    If ``value`` is ``"<b>Joel</b> <button>is</button> a <span>slug</span>"`` the
    567567    return value will be ``"Joel is a slug"``.
    568568
     569    .. versionchanged:: 1.6
     570
     571        For improved safety, ``strip_tags`` is now parser-based. That means that
     572        the fed ``value`` should contain valid HTML. Typically, unmatched tags
     573        might result in content disappearing.
     574
     575
    569576.. function:: remove_tags(value, tags)
    570577
    571578    Removes a space-separated list of [X]HTML tag names from the output.
  • tests/utils_tests/test_html.py

    diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py
    index c3e9f7c..d9fbc6d 100644
    a b class TestUtilsHtml(TestCase):  
    6969            ('<adf>a', 'a'),
    7070            ('</adf>a', 'a'),
    7171            ('<asdf><asdf>e', 'e'),
    72             ('hi, <f x', 'hi, <f x'),
    73             ('</fe', '</fe'),
     72            ('hi, <f x', 'hi, '),
     73            ('</fe', ''),
    7474            ('<x>b<y>', 'b'),
    7575            ('a<p onclick="alert(\'<test>\')">b</p>c', 'abc'),
    7676            ('a<p a >b</p>c', 'abc'),
Back to Top