diff -r 8aa053b99c24 -r c9d923f5d8ae mercurial/minirst.py --- a/mercurial/minirst.py Sat Feb 09 21:51:21 2013 +0000 +++ b/mercurial/minirst.py Sat Feb 09 17:44:25 2013 -0500 @@ -22,6 +22,8 @@ import util, encoding from i18n import _ +import cgi + def section(s): return "%s\n%s\n\n" % (s, "\"" * encoding.colwidth(s)) @@ -524,6 +526,9 @@ headernest = '' listnest = [] + def escape(s): + return cgi.escape(s, True) + def openlist(start, level): if not listnest or listnest[-1][0] != start: listnest.append((start, level)) @@ -537,34 +542,34 @@ lines = b['lines'] if btype == 'admonition': - admonition = _admonitiontitles[b['admonitiontitle']] - text = ' '.join(map(str.strip, lines)) + admonition = escape(_admonitiontitles[b['admonitiontitle']]) + text = escape(' '.join(map(str.strip, lines))) out.append('

\n%s %s\n

\n' % (admonition, text)) elif btype == 'paragraph': - out.append('

\n%s\n

\n' % '\n'.join(lines)) + out.append('

\n%s\n

\n' % escape('\n'.join(lines))) elif btype == 'margin': pass elif btype == 'literal': - out.append('
\n%s\n
\n' % '\n'.join(lines)) + out.append('
\n%s\n
\n' % escape('\n'.join(lines))) elif btype == 'section': i = b['underline'] if i not in headernest: headernest += i level = headernest.index(i) + 1 - out.append('%s\n' % (level, lines[0], level)) + out.append('%s\n' % (level, escape(lines[0]), level)) elif btype == 'table': table = b['table'] t = [] for row in table: l = [] - for v in zip(row): - l.append('%s' % v) + for v in row: + l.append('%s' % escape(v)) t.append(' %s\n' % ''.join(l)) out.append('\n%s
\n' % ''.join(t)) elif btype == 'definition': openlist('dl', level) - term = lines[0] - text = ' '.join(map(str.strip, lines[1:])) + term = escape(lines[0]) + text = escape(' '.join(map(str.strip, lines[1:]))) out.append('
%s\n
%s\n' % (term, text)) elif btype == 'bullet': bullet, head = lines[0].split(' ', 1) @@ -572,16 +577,16 @@ openlist('ul', level) else: openlist('ol', level) - out.append('
  • %s\n' % ' '.join([head] + lines[1:])) + out.append('
  • %s\n' % escape(' '.join([head] + lines[1:]))) elif btype == 'field': openlist('dl', level) - key = b['key'] - text = ' '.join(map(str.strip, lines)) + key = escape(b['key']) + text = escape(' '.join(map(str.strip, lines))) out.append('
    %s\n
    %s\n' % (key, text)) elif btype == 'option': openlist('dl', level) - opt = b['optstr'] - desc = ' '.join(map(str.strip, lines)) + opt = escape(b['optstr']) + desc = escape(' '.join(map(str.strip, lines))) out.append('
    %s\n
    %s\n' % (opt, desc)) # close lists if indent level of next block is lower