Ticket #1085: 0001-Fix-1085-allow-h1-h2-in-html-cleanup.patch

File 0001-Fix-1085-allow-h1-h2-in-html-cleanup.patch, 1.8 KB (added by Loic Dachary, 8 years ago)
  • mediagoblin/tests/test_util.py

    From d187d47296c30c915930ee5762c143cb431ab170 Mon Sep 17 00:00:00 2001
    From: Loic Dachary <loic@dachary.org>
    Date: Tue, 12 Jan 2016 19:29:46 +0100
    Subject: [PATCH] Fix #1085 - allow h1/h2 in html cleanup
    
    The markdown conversion of
    
        bin/python -m markdown <<EOF
        AAAAAAA
        =======
    
        BBBBBBB
        -------
    
        CCCCCCC
        EOF
    
        <h1>AAAAAAA</h1>
        <h2>BBBBBBB</h2>
        <p>CCCCCCC</p>
    
    Must not be stripped of the h1/h2 elements.
    
    Signed-off-by: Loic Dachary <loic@dachary.org>
    ---
     mediagoblin/tests/test_util.py | 6 +++++-
     mediagoblin/tools/text.py      | 2 +-
     2 files changed, 6 insertions(+), 2 deletions(-)
    
    diff --git a/mediagoblin/tests/test_util.py b/mediagoblin/tests/test_util.py
    index 8193233..970ea1f 100644
    a b def test_html_cleaner():  
    169169    result = text.clean_html(
    170170        '<p>Hi everybody! '
    171171        '<img src="http://example.org/huge-purple-barney.png" /></p>\n'
    172         '<p>:)</p>')
     172        '<p>:)</p>'
     173        '<h1>H1</h1>'
     174        '<h2>H2</h2>')
    173175    assert result == (
    174176        '<div>'
    175177        '<p>Hi everybody! </p>\n'
    176178        '<p>:)</p>'
     179        '<h1>H1</h1>'
     180        '<h2>H2</h2>'
    177181        '</div>')
    178182
    179183    # Remove evil javascript
  • mediagoblin/tools/text.py

    diff --git a/mediagoblin/tools/text.py b/mediagoblin/tools/text.py
    index 96df49d..b253696 100644
    a b HTML_CLEANER = Cleaner(  
    3737    annoying_tags=True,
    3838    allow_tags=[
    3939        'div', 'b', 'i', 'em', 'strong', 'p', 'ul', 'ol', 'li', 'a', 'br',
    40         'pre', 'code'],
     40        'pre', 'code', 'h1', 'h2'],
    4141    remove_unknown_tags=False,  # can't be used with allow_tags
    4242    safe_attrs_only=True,
    4343    add_nofollow=True,  # for now