Project

General

Profile

« Previous | Next » 

Revision 1809

xml_dom.py: Added clean_comment() and mk_comment() to properly sanitize comment contents (comments can't contain '--')

View differences:

lib/xml_dom.py
2 2

  
3 3
import cgi
4 4
from HTMLParser import HTMLParser
5
import re
5 6
from xml.dom import Node
6 7
import xml.dom.minidom as minidom
7 8

  
......
59 60
        if not is_comment(child): return False
60 61
    return True
61 62

  
63
def clean_comment(str_):
64
    '''Sanitizes comment node contents. Strips invalid strings.'''
65
    return re.sub(r'-{2,}', r'-', str_) # comments can't contain '--'
66

  
67
def mk_comment(doc, str_): return doc.createComment(clean_comment(str_))
68

  
62 69
##### Child nodes that are elements
63 70

  
64 71
class NodeElemIter:

Also available in: Unified diff