Skip to content

Commit a2377e1

Browse files
committed
When safe mode is 'escape', don't allow bad html to stop further processing.
See tests/html4_safe/html_then_blockquote.(txt|html). It looks like having unclosed block-level html elements was causing further processing not to happen, even in the case where we're escaping HTML. Since we're escaping HTML, it seems like it shouldn't affect processing at all. This changes output results in a couple of other tests, but the new output seems reasonable to me.
1 parent 542324b commit a2377e1

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

markdown/preprocessors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
def build_preprocessors(md_instance, **kwargs):
1515
""" Build the default set of preprocessors used by Markdown. """
1616
preprocessors = odict.OrderedDict()
17-
preprocessors["html_block"] = HtmlBlockPreprocessor(md_instance)
17+
if md_instance.safeMode != 'escape':
18+
preprocessors["html_block"] = HtmlBlockPreprocessor(md_instance)
1819
preprocessors["reference"] = ReferencePreprocessor(md_instance)
1920
return preprocessors
2021

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<p>to:</p>
2+
<p>&lt;td /&gt;&lt;td style=&quot;text-align: center; white-space: nowrap;&quot;&gt;&lt;br /&gt;</p>
3+
<blockquote>
4+
<p>3) You don't need to alter all localization files.
5+
Adding the new labels to the en_US files will do it.</p>
6+
</blockquote>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
to:
2+
3+
<td /><td style="text-align: center; white-space: nowrap;"><br />
4+
5+
> 3) You don't need to alter all localization files.
6+
> Adding the new labels to the en_US files will do it.

tests/safe_mode/inline-html-simple.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,20 @@
2929
<pre><code>&lt;!-- Comment --&gt;
3030
</code></pre>
3131
<p>Just plain comment, with trailing spaces on the line:</p>
32-
<p>&lt;!-- foo --&gt;</p>
32+
<p>&lt;!-- foo --&gt; <br />
33+
</p>
3334
<p>Code:</p>
3435
<pre><code>&lt;hr /&gt;
3536
</code></pre>
3637
<p>Hr's:</p>
3738
<p>&lt;hr&gt;</p>
3839
<p>&lt;hr/&gt;</p>
3940
<p>&lt;hr /&gt;</p>
40-
<p>&lt;hr&gt;</p>
41-
<p>&lt;hr/&gt;</p>
42-
<p>&lt;hr /&gt;</p>
41+
<p>&lt;hr&gt; <br />
42+
</p>
43+
<p>&lt;hr/&gt;<br />
44+
</p>
45+
<p>&lt;hr /&gt; </p>
4346
<p>&lt;hr class=&quot;foo&quot; id=&quot;bar&quot; /&gt;</p>
4447
<p>&lt;hr class=&quot;foo&quot; id=&quot;bar&quot;/&gt;</p>
4548
<p>&lt;hr class=&quot;foo&quot; id=&quot;bar&quot; &gt;</p>

tests/safe_mode/script_tags.html

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
<p>This should be stripped/escaped in safe_mode.</p>
22
<p>&lt;script&gt;
3-
alert(&quot;Hello world!&quot;)
3+
alert("Hello world!")
44
&lt;/script&gt;</p>
55
<p>With blank lines.</p>
6-
<p>&lt;script&gt;
7-
8-
alert(&quot;Hello world!&quot;)
9-
10-
&lt;/script&gt;</p>
6+
<p>&lt;script&gt;</p>
7+
<p>alert("Hello world!")</p>
8+
<p>&lt;/script&gt;</p>
119
<p>Now with some weirdness</p>
1210
<p><code>&lt;script &lt;!--
1311
alert("Hello world!")
1412
&lt;/script &lt;&gt;</code> `</p>
1513
<p>Try another way.</p>
1614
<p>&lt;script &lt;!--
1715
alert(&quot;Hello world!&quot;)
18-
&lt;/script &lt;&gt;
19-
20-
This time with blank lines.
21-
22-
&lt;script &lt;!--
23-
24-
alert(&quot;Hello world!&quot;)
25-
26-
&lt;/script &lt;&gt;
27-
28-
</p>
16+
&lt;/script &lt;&gt;</p>
17+
<p>This time with blank lines.</p>
18+
<p>&lt;script &lt;!--</p>
19+
<p>alert("Hello world!")</p>
20+
<p>&lt;/script &lt;&gt;</p>

0 commit comments

Comments
 (0)