# HG changeset patch # User cmlenz # Date 1195760585 0 # Node ID 14aa86c3e5142008cd5b0b53480cb7fee7732227 # Parent 23b5138fd8353a2a45954500027b70b0a8f8f7f6 The `striptags` function now also removes HTML/XML-style comments. Closes #150. Thanks to Armin Ronacher for the report and suggested fix. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -36,6 +36,8 @@ * Python code blocks inside match templates are now executed (ticket #155). * The template engine plugin no longer adds the `default_doctype` when the `fragment` parameter is `True`. + * The `striptags` function now also removes HTML/XML-style comments (ticket + #150). Version 0.4.4 diff --git a/genshi/util.py b/genshi/util.py --- a/genshi/util.py +++ b/genshi/util.py @@ -228,7 +228,7 @@ return ref return _STRIPENTITIES_RE.sub(_replace_entity, text) -_STRIPTAGS_RE = re.compile(r'<[^>]*?>') +_STRIPTAGS_RE = re.compile(r'(|<[^>]*>)') def striptags(text): """Return a copy of the text with any XML/HTML tags removed. @@ -239,6 +239,11 @@ >>> striptags('Foo
') 'Foo' + HTML/XML comments are stripped, too: + + >>> striptags('test') + 'test' + :param text: the string to remove tags from :return: the text with tags removed """