changeset 655:14aa86c3e514 trunk

The `striptags` function now also removes HTML/XML-style comments. Closes #150. Thanks to Armin Ronacher for the report and suggested fix.
author cmlenz
date Thu, 22 Nov 2007 19:43:05 +0000
parents 23b5138fd835
children f3bc1de7138d
files ChangeLog genshi/util.py
diffstat 2 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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<br />')
     'Foo'
     
+    HTML/XML comments are stripped, too:
+    
+    >>> striptags('<!-- <blub>hehe</blah> -->test')
+    'test'
+    
     :param text: the string to remove tags from
     :return: the text with tags removed
     """
Copyright (C) 2012-2017 Edgewall Software