##// END OF EJS Templates
minirst: CGI escape strings prior to embedding it in the HTML
Dan Villiom Podlaski Christiansen -
r18750:c9d923f5 default
parent child Browse files
Show More
@@ -22,6 +22,8 b' import re'
22 import util, encoding
22 import util, encoding
23 from i18n import _
23 from i18n import _
24
24
25 import cgi
26
25 def section(s):
27 def section(s):
26 return "%s\n%s\n\n" % (s, "\"" * encoding.colwidth(s))
28 return "%s\n%s\n\n" % (s, "\"" * encoding.colwidth(s))
27
29
@@ -524,6 +526,9 b' def formathtml(blocks):'
524 headernest = ''
526 headernest = ''
525 listnest = []
527 listnest = []
526
528
529 def escape(s):
530 return cgi.escape(s, True)
531
527 def openlist(start, level):
532 def openlist(start, level):
528 if not listnest or listnest[-1][0] != start:
533 if not listnest or listnest[-1][0] != start:
529 listnest.append((start, level))
534 listnest.append((start, level))
@@ -537,34 +542,34 b' def formathtml(blocks):'
537 lines = b['lines']
542 lines = b['lines']
538
543
539 if btype == 'admonition':
544 if btype == 'admonition':
540 admonition = _admonitiontitles[b['admonitiontitle']]
545 admonition = escape(_admonitiontitles[b['admonitiontitle']])
541 text = ' '.join(map(str.strip, lines))
546 text = escape(' '.join(map(str.strip, lines)))
542 out.append('<p>\n<b>%s</b> %s\n</p>\n' % (admonition, text))
547 out.append('<p>\n<b>%s</b> %s\n</p>\n' % (admonition, text))
543 elif btype == 'paragraph':
548 elif btype == 'paragraph':
544 out.append('<p>\n%s\n</p>\n' % '\n'.join(lines))
549 out.append('<p>\n%s\n</p>\n' % escape('\n'.join(lines)))
545 elif btype == 'margin':
550 elif btype == 'margin':
546 pass
551 pass
547 elif btype == 'literal':
552 elif btype == 'literal':
548 out.append('<pre>\n%s\n</pre>\n' % '\n'.join(lines))
553 out.append('<pre>\n%s\n</pre>\n' % escape('\n'.join(lines)))
549 elif btype == 'section':
554 elif btype == 'section':
550 i = b['underline']
555 i = b['underline']
551 if i not in headernest:
556 if i not in headernest:
552 headernest += i
557 headernest += i
553 level = headernest.index(i) + 1
558 level = headernest.index(i) + 1
554 out.append('<h%d>%s</h%d>\n' % (level, lines[0], level))
559 out.append('<h%d>%s</h%d>\n' % (level, escape(lines[0]), level))
555 elif btype == 'table':
560 elif btype == 'table':
556 table = b['table']
561 table = b['table']
557 t = []
562 t = []
558 for row in table:
563 for row in table:
559 l = []
564 l = []
560 for v in zip(row):
565 for v in row:
561 l.append('<td>%s</td>' % v)
566 l.append('<td>%s</td>' % escape(v))
562 t.append(' <tr>%s</tr>\n' % ''.join(l))
567 t.append(' <tr>%s</tr>\n' % ''.join(l))
563 out.append('<table>\n%s</table>\n' % ''.join(t))
568 out.append('<table>\n%s</table>\n' % ''.join(t))
564 elif btype == 'definition':
569 elif btype == 'definition':
565 openlist('dl', level)
570 openlist('dl', level)
566 term = lines[0]
571 term = escape(lines[0])
567 text = ' '.join(map(str.strip, lines[1:]))
572 text = escape(' '.join(map(str.strip, lines[1:])))
568 out.append(' <dt>%s\n <dd>%s\n' % (term, text))
573 out.append(' <dt>%s\n <dd>%s\n' % (term, text))
569 elif btype == 'bullet':
574 elif btype == 'bullet':
570 bullet, head = lines[0].split(' ', 1)
575 bullet, head = lines[0].split(' ', 1)
@@ -572,16 +577,16 b' def formathtml(blocks):'
572 openlist('ul', level)
577 openlist('ul', level)
573 else:
578 else:
574 openlist('ol', level)
579 openlist('ol', level)
575 out.append(' <li> %s\n' % ' '.join([head] + lines[1:]))
580 out.append(' <li> %s\n' % escape(' '.join([head] + lines[1:])))
576 elif btype == 'field':
581 elif btype == 'field':
577 openlist('dl', level)
582 openlist('dl', level)
578 key = b['key']
583 key = escape(b['key'])
579 text = ' '.join(map(str.strip, lines))
584 text = escape(' '.join(map(str.strip, lines)))
580 out.append(' <dt>%s\n <dd>%s\n' % (key, text))
585 out.append(' <dt>%s\n <dd>%s\n' % (key, text))
581 elif btype == 'option':
586 elif btype == 'option':
582 openlist('dl', level)
587 openlist('dl', level)
583 opt = b['optstr']
588 opt = escape(b['optstr'])
584 desc = ' '.join(map(str.strip, lines))
589 desc = escape(' '.join(map(str.strip, lines)))
585 out.append(' <dt>%s\n <dd>%s\n' % (opt, desc))
590 out.append(' <dt>%s\n <dd>%s\n' % (opt, desc))
586
591
587 # close lists if indent level of next block is lower
592 # close lists if indent level of next block is lower
@@ -1519,7 +1519,7 b' Dish up an empty repo; serve it cold.'
1519 </p>
1519 </p>
1520 <p>
1520 <p>
1521 The files will be added to the repository at the next commit. To
1521 The files will be added to the repository at the next commit. To
1522 undo an add before that, see "hg forget".
1522 undo an add before that, see &quot;hg forget&quot;.
1523 </p>
1523 </p>
1524 <p>
1524 <p>
1525 If no names are given, add all files to the repository.
1525 If no names are given, add all files to the repository.
@@ -1633,8 +1633,8 b' Dish up an empty repo; serve it cold.'
1633 </p>
1633 </p>
1634 <p>
1634 <p>
1635 This command schedules the files to be removed at the next commit.
1635 This command schedules the files to be removed at the next commit.
1636 To undo a remove before that, see "hg revert". To undo added
1636 To undo a remove before that, see &quot;hg revert&quot;. To undo added
1637 files, see "hg forget".
1637 files, see &quot;hg forget&quot;.
1638 </p>
1638 </p>
1639 <p>
1639 <p>
1640 Returns 0 on success, 1 if any warnings encountered.
1640 Returns 0 on success, 1 if any warnings encountered.
@@ -1754,20 +1754,20 b' Dish up an empty repo; serve it cold.'
1754 Any other string is treated as a bookmark, tag, or branch name. A
1754 Any other string is treated as a bookmark, tag, or branch name. A
1755 bookmark is a movable pointer to a revision. A tag is a permanent name
1755 bookmark is a movable pointer to a revision. A tag is a permanent name
1756 associated with a revision. A branch name denotes the tipmost revision
1756 associated with a revision. A branch name denotes the tipmost revision
1757 of that branch. Bookmark, tag, and branch names must not contain the ":"
1757 of that branch. Bookmark, tag, and branch names must not contain the &quot;:&quot;
1758 character.
1758 character.
1759 </p>
1759 </p>
1760 <p>
1760 <p>
1761 The reserved name "tip" always identifies the most recent revision.
1761 The reserved name &quot;tip&quot; always identifies the most recent revision.
1762 </p>
1762 </p>
1763 <p>
1763 <p>
1764 The reserved name "null" indicates the null revision. This is the
1764 The reserved name &quot;null&quot; indicates the null revision. This is the
1765 revision of an empty repository, and the parent of revision 0.
1765 revision of an empty repository, and the parent of revision 0.
1766 </p>
1766 </p>
1767 <p>
1767 <p>
1768 The reserved name "." indicates the working directory parent. If no
1768 The reserved name &quot;.&quot; indicates the working directory parent. If no
1769 working directory is checked out, it is equivalent to null. If an
1769 working directory is checked out, it is equivalent to null. If an
1770 uncommitted merge is in progress, "." is the revision of the first
1770 uncommitted merge is in progress, &quot;.&quot; is the revision of the first
1771 parent.
1771 parent.
1772 </p>
1772 </p>
1773
1773
@@ -605,7 +605,7 b' Please see "hg add".'
605 html format:
605 html format:
606 ----------------------------------------------------------------------
606 ----------------------------------------------------------------------
607 <p>
607 <p>
608 Please see "hg add".
608 Please see &quot;hg add&quot;.
609 </p>
609 </p>
610 ----------------------------------------------------------------------
610 ----------------------------------------------------------------------
611
611
@@ -645,7 +645,7 b' html format:'
645 <h1>Title</h1>
645 <h1>Title</h1>
646 <h2>Section</h2>
646 <h2>Section</h2>
647 <h3>Subsection</h3>
647 <h3>Subsection</h3>
648 <h2>Markup: "foo" and "hg help"</h2>
648 <h2>Markup: &quot;foo&quot; and &quot;hg help&quot;</h2>
649 ----------------------------------------------------------------------
649 ----------------------------------------------------------------------
650
650
651 == admonitions ==
651 == admonitions ==
General Comments 0
You need to be logged in to leave comments. Login now