From c14195a0a2e6f9b234cdc247507c2609943498c5 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 13 Jan 2019 11:59:36 +0200 Subject: Fix: undo HTML escaping of code blocks --- NEWS | 2 ++ htmlesc.scenario | 13 +++++++++++++ yarn.tests/htmlescape.script | 5 +++++ yarnlib/mdparser.py | 5 ++++- 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 htmlesc.scenario create mode 100755 yarn.tests/htmlescape.script diff --git a/NEWS b/NEWS index 215b42a..623a05c 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ This file summarizes changes between releases of cmdtest. Version 0.32+git, not yet released ---------------------------------- +* Undo HTML escaping of code blocks done by the Python Markdown + parser. Version 0.32, released 2018-02-24 ---------------------------------- diff --git a/htmlesc.scenario b/htmlesc.scenario new file mode 100644 index 0000000..cb80865 --- /dev/null +++ b/htmlesc.scenario @@ -0,0 +1,13 @@ +An HTML escaping scenario +========================= + +Test HTML escapes in IMPLEMENTS code. At some point after Debian 9 was +released, the Python markdown library yarn uses started to HTML escape +code blocks. This breaks any shell scripts that use redirection. Make +sure this works. + + SCENARIO html escaping + THEN greet + + IMPLEMENTS THEN greet + echo hello > /dev/null diff --git a/yarn.tests/htmlescape.script b/yarn.tests/htmlescape.script new file mode 100755 index 0000000..b3a7840 --- /dev/null +++ b/yarn.tests/htmlescape.script @@ -0,0 +1,5 @@ +#!/bin/sh + +set -eu + +./run-yarn htmlesc.scenario diff --git a/yarnlib/mdparser.py b/yarnlib/mdparser.py index 4bd59d3..67851ec 100644 --- a/yarnlib/mdparser.py +++ b/yarnlib/mdparser.py @@ -17,6 +17,7 @@ import logging +import HTMLParser import markdown import StringIO from markdown.treeprocessors import Treeprocessor @@ -40,10 +41,12 @@ class GatherCodeBlocks(Treeprocessor): self.blocks = blocks def run(self, root): + h = HTMLParser.HTMLParser() for child in root.getchildren(): if child.tag == 'pre': code = child.find('code') - self.blocks.append(code.text) + text = h.unescape(code.text) + self.blocks.append(text) return root # This is the Python Markdown extension to call the code block -- cgit v1.2.1