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():
|
169 | 169 | result = text.clean_html( |
170 | 170 | '<p>Hi everybody! ' |
171 | 171 | '<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>') |
173 | 175 | assert result == ( |
174 | 176 | '<div>' |
175 | 177 | '<p>Hi everybody! </p>\n' |
176 | 178 | '<p>:)</p>' |
| 179 | '<h1>H1</h1>' |
| 180 | '<h2>H2</h2>' |
177 | 181 | '</div>') |
178 | 182 | |
179 | 183 | # Remove evil javascript |
diff --git a/mediagoblin/tools/text.py b/mediagoblin/tools/text.py
index 96df49d..b253696 100644
a
|
b
|
HTML_CLEANER = Cleaner(
|
37 | 37 | annoying_tags=True, |
38 | 38 | allow_tags=[ |
39 | 39 | 'div', 'b', 'i', 'em', 'strong', 'p', 'ul', 'ol', 'li', 'a', 'br', |
40 | | 'pre', 'code'], |
| 40 | 'pre', 'code', 'h1', 'h2'], |
41 | 41 | remove_unknown_tags=False, # can't be used with allow_tags |
42 | 42 | safe_attrs_only=True, |
43 | 43 | add_nofollow=True, # for now |