Ticket #2455: dont_escape_wiki_text_beforehand-r2636.2.patch
| File dont_escape_wiki_text_beforehand-r2636.2.patch, 7.5 KB (added by moschny at ipd.uni-karlsruhe.de, 3 years ago) |
|---|
-
trac/ticket/query.py
609 609 def _format_link(self, formatter, ns, query, label): 610 610 if query[0] == '?': 611 611 return '<a class="query" href="%s">%s</a>' \ 612 % (escape(formatter.href.query() ) + query.replace(' ', '+'),612 % (escape(formatter.href.query() + query.replace(' ', '+')), 613 613 label) 614 614 else: 615 615 from trac.ticket.query import Query, QuerySyntaxError 616 616 try: 617 query = Query.from_string(formatter.env, unescape(query))617 query = Query.from_string(formatter.env, query) 618 618 return '<a class="query" href="%s">%s</a>' \ 619 619 % (escape(query.get_href()), label) 620 620 except QuerySyntaxError, e: -
trac/Search.py
238 238 239 239 def _format_link(self, formatter, ns, query, label): 240 240 if query and query[0] == '?': 241 href = formatter.href.search() + \ 242 query.replace('&', '&').replace(' ', '+') 241 href = formatter.href.search() + query.replace(' ', '+') 243 242 else: 244 243 href = formatter.href.search(q=query) 245 244 return '<a class="search" href="%s">%s</a>' % (escape(href), label) -
trac/wiki/tests/wiki-tests.txt
115 115 ticket:1 116 116 This ticket is the first one 117 117 changeset:123> 118 changeset:123& 118 119 ------------------------------ 119 120 <p> 120 121 Add-on to <a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>: … … 122 123 <a class="missing ticket" href="/ticket/1" rel="nofollow">ticket:1</a> 123 124 This ticket is the first one 124 125 <a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>> 126 <a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>& 125 127 </p> 126 128 ------------------------------ 127 129 Add-on to <a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>: … … 129 131 <a class="missing ticket" href="/ticket/1" rel="nofollow">ticket:1</a> 130 132 This ticket is the first one 131 133 <a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>> 134 <a class="missing changeset" href="/changeset/123" rel="nofollow">changeset:123</a>& 132 135 ============================== 133 136 CamelCase AlabamA ABc AlaBamA FooBar 134 137 ------------------------------ -
trac/wiki/formatter.py
137 137 QUOTED_STRING = r"'[^']+'|\"[^\"]+\"" 138 138 139 139 SHREF_TARGET_FIRST = r"[\w/?!#@]" 140 SHREF_TARGET_MIDDLE = r"(?:\|(?=[^|\s])| &(?!lt;|gt;)|[^|&\s])"140 SHREF_TARGET_MIDDLE = r"(?:\|(?=[^|\s])|[^|<>\s])" 141 141 SHREF_TARGET_LAST = r"[a-zA-Z0-9/=]" # we don't want "_" 142 142 143 143 LHREF_RELATIVE_TARGET = r"[/.][^\s[\]]*" … … 147 147 # between _pre_rules and _post_rules 148 148 149 149 _pre_rules = [ 150 r"(?P<htmlescape>[&<>])", 150 151 # Font styles 151 152 r"(?P<bolditalic>%s)" % BOLDITALIC_TOKEN, 152 153 r"(?P<bold>%s)" % BOLD_TOKEN, … … 296 297 297 298 def _make_link(self, ns, target, match, label): 298 299 if ns in self.link_resolvers: 299 return self.link_resolvers[ns](self, ns, target, label) 300 return self.link_resolvers[ns](self, ns, target, 301 util.escape(label, False)) 300 302 elif target.startswith('//') or ns == "mailto": 301 303 return self._make_ext_link(ns+':'+target, label) 302 304 else: 303 return match305 return util.escape(match) 304 306 305 307 def _make_ext_link(self, url, text, title=''): 308 url = util.escape(url) 309 text, title = util.escape(text), util.escape(title) 306 310 title_attr = title and ' title="%s"' % title or '' 307 311 if Formatter.img_re.search(url) and self.flavor != 'oneliner': 308 312 return '<img src="%s" alt="%s" />' % (url, title or text) … … 313 317 return '<a href="%s"%s>%s</a>' % (url, title_attr, text) 314 318 315 319 def _make_relative_link(self, url, text): 320 url, text = util.escape(url), util.escape(text) 316 321 if Formatter.img_re.search(url) and self.flavor != 'oneliner': 317 322 return '<img src="%s" alt="%s" />' % (url, text) 318 323 if url.startswith('//'): # only the protocol will be kept … … 364 369 # the tickethref regexp 365 370 return match 366 371 372 def _htmlescape_formatter(self, match, fullmatch): 373 return match == "&" and "&" or match == "<" and "<" or ">" 374 367 375 def _macro_formatter(self, match, fullmatch): 368 376 name = fullmatch.group('macroname') 369 377 if name in ['br', 'BR']: 370 378 return '<br />' 371 379 args = fullmatch.group('macroargs') 372 args = util.unescape(args)373 380 try: 374 381 macro = WikiProcessor(self.env, name) 375 382 return macro.process(self.req, args, 1) … … 389 396 depth = min(len(fullmatch.group('hdepth')), 5) 390 397 heading = match[depth + 1:len(match) - depth - 1] 391 398 392 text = wiki_to_oneliner(util.unescape(heading), self.env, self.db, 393 self._absurls) 399 text = wiki_to_oneliner(heading, self.env, self.db, self._absurls) 394 400 sans_markup = re.sub(r'</?\w+(?: .*?)?>', '', text) 395 401 396 402 anchor = self._anchor_re.sub('', sans_markup.decode('utf-8')) … … 599 605 self.close_def_list() 600 606 continue 601 607 602 line = util.escape(line, False)603 608 if escape_newlines: 604 609 line += ' [[BR]]' 605 610 self.in_list_item = False … … 646 651 # Override a few formatters to disable some wiki syntax in "oneliner"-mode 647 652 def _list_formatter(self, match, fullmatch): return match 648 653 def _indent_formatter(self, match, fullmatch): return match 649 def _heading_formatter(self, match, fullmatch): return match 650 def _definition_formatter(self, match, fullmatch): return match 654 def _heading_formatter(self, match, fullmatch): 655 return util.escape(match, False) 656 def _definition_formatter(self, match, fullmatch): 657 return util.escape(match, False) 651 658 def _table_cell_formatter(self, match, fullmatch): return match 652 659 def _last_table_cell_formatter(self, match, fullmatch): return match 653 660 … … 687 694 if shorten: 688 695 result = util.shorten_line(result) 689 696 690 result = re.sub(self.rules, self.replace, util.escape(result, False))697 result = re.sub(self.rules, self.replace, result) 691 698 result = result.replace('[...]', '[…]') 692 699 if result.endswith('...'): 693 700 result = result[:-3] + '…' … … 739 746 depth = min(len(fullmatch.group('hdepth')), 5) 740 747 heading = match[depth + 1:len(match) - depth - 1] 741 748 anchor = self._anchors[-1] 742 text = wiki_to_oneliner(util.unescape(heading), self.env, self.db, 743 self._absurls) 749 text = wiki_to_oneliner(heading, self.env, self.db, self._absurls) 744 750 text = re.sub(r'</?a(?: .*?)?>', '', text) # Strip out link tags 745 751 self.outline.append((depth, '<a href="#%s">%s</a>' % (anchor, text))) 746 752
