Ticket #1153: dont_escape_wiki_text_beforehand.patch
| File dont_escape_wiki_text_beforehand.patch, 7.8 kB (added by cboos, 3 years ago) |
|---|
-
trac/ticket/query.py
590 590 def _format_link(self, formatter, ns, query, label): 591 591 if query[0] == '?': 592 592 return '<a class="query" href="%s">%s</a>' \ 593 % (escape(formatter.href.query() ) + query.replace(' ', '+'),593 % (escape(formatter.href.query() + query.replace(' ', '+')), 594 594 label) 595 595 else: 596 596 from trac.ticket.query import Query, QuerySyntaxError 597 597 try: 598 query = Query.from_string(formatter.env, unescape(query))598 query = Query.from_string(formatter.env, query) 599 599 return '<a class="query" href="%s">%s</a>' \ 600 600 % (escape(query.get_href()), label) 601 601 except QuerySyntaxError, e: -
trac/Search.py
237 237 238 238 def _format_link(self, formatter, ns, query, label): 239 239 if query and query[0] == '?': 240 href = formatter.href.search() + \ 241 query.replace('&', '&').replace(' ', '+') 240 href = formatter.href.search() + query.replace(' ', '+') 242 241 else: 243 242 href = formatter.href.search(q=query) 244 243 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
138 138 QUOTED_STRING = r"'[^']+'|\"[^\"]+\"" 139 139 140 140 SHREF_TARGET_FIRST = r"[\w/?!#@]" 141 SHREF_TARGET_MIDDLE = r"(?:\|(?=[^|\s])| &(?!lt;|gt;)|[^|&\s])"141 SHREF_TARGET_MIDDLE = r"(?:\|(?=[^|\s])|[^|<>\s])" 142 142 SHREF_TARGET_LAST = r"[a-zA-Z0-9/=]" # we don't want "_" 143 143 144 144 LHREF_RELATIVE_TARGET = r"[/.][^\s[\]]*" … … 148 148 # between _pre_rules and _post_rules 149 149 150 150 _pre_rules = [ 151 r"(?P<htmlescape>[&<>])", 151 152 # Font styles 152 153 r"(?P<bolditalic>%s)" % BOLDITALIC_TOKEN, 153 154 r"(?P<bold>%s)" % BOLD_TOKEN, … … 297 298 298 299 def _make_link(self, ns, target, match, label): 299 300 if ns in self.link_resolvers: 300 return self.link_resolvers[ns](self, ns, target, label) 301 return self.link_resolvers[ns](self, ns, target, 302 util.escape(label, False)) 301 303 elif target.startswith('//') or ns == "mailto": 302 304 return self._make_ext_link(ns+':'+target, label) 303 305 else: 304 return match306 return util.escape(match) 305 307 306 308 def _make_ext_link(self, url, text, title=''): 307 title_attr = title and ' title="%s"' % title or '' 309 url = util.escape(url) 310 title_attr = title and ' title="%s"' % util.escape(title) or '' 308 311 if Formatter.img_re.search(url) and self.flavor != 'oneliner': 309 return '<img src="%s" alt="%s" />' % (url, title or text) 312 return '<img src="%s" alt="%s" />' % (url, 313 util.escape(title or text)) 310 314 if not url.startswith(self._local): 311 315 return '<a class="ext-link" href="%s"%s><span class="icon">' \ 312 316 '</span>%s</a>' % (url, title_attr, text) … … 314 318 return '<a href="%s"%s>%s</a>' % (url, title_attr, text) 315 319 316 320 def _make_relative_link(self, url, text): 321 url, text = util.escape(url), util.escape(text) 317 322 if Formatter.img_re.search(url) and self.flavor != 'oneliner': 318 323 return '<img src="%s" alt="%s" />' % (url, text) 319 324 if url.startswith('//'): # only the protocol will be kept … … 365 370 # the tickethref regexp 366 371 return match 367 372 373 def _htmlescape_formatter(self, match, fullmatch): 374 return match == "&" and "&" or match == "<" and "<" or ">" 375 368 376 def _macro_formatter(self, match, fullmatch): 369 377 name = fullmatch.group('macroname') 370 378 if name in ['br', 'BR']: 371 379 return '<br />' 372 380 args = fullmatch.group('macroargs') 373 args = util.unescape(args)374 381 try: 375 382 macro = WikiProcessor(self.env, name) 376 383 return macro.process(self.req, args, 1) … … 390 397 depth = min(len(fullmatch.group('hdepth')), 5) 391 398 heading = match[depth + 1:len(match) - depth - 1] 392 399 393 text = wiki_to_oneliner(util.unescape(heading), self.env, self.db, 394 self._absurls) 400 text = wiki_to_oneliner(heading, self.env, self.db, self._absurls) 395 401 sans_markup = re.sub(r'</?\w+(?: .*?)?>', '', text) 396 402 397 403 anchor = self._anchor_re.sub('', sans_markup.decode('utf-8')) … … 600 606 self.close_def_list() 601 607 continue 602 608 603 line = util.escape(line, False)604 609 if escape_newlines: 605 610 line += ' [[BR]]' 606 611 self.in_list_item = False … … 643 648 # Override a few formatters to disable some wiki syntax in "oneliner"-mode 644 649 def _list_formatter(self, match, fullmatch): return match 645 650 def _indent_formatter(self, match, fullmatch): return match 646 def _heading_formatter(self, match, fullmatch): return match 647 def _definition_formatter(self, match, fullmatch): return match 651 def _heading_formatter(self, match, fullmatch): 652 return util.escape(match, False) 653 def _definition_formatter(self, match, fullmatch): 654 return util.escape(match, False) 648 655 def _table_cell_formatter(self, match, fullmatch): return match 649 656 def _last_table_cell_formatter(self, match, fullmatch): return match 650 657 … … 664 671 self.out = out 665 672 self._open_tags = [] 666 673 667 result = re.sub(self.rules, self.replace, util.escape(text.strip(), False))674 result = re.sub(self.rules, self.replace, text.strip()) 668 675 # Close all open 'one line'-tags 669 676 result += self.close_tag(None) 670 677 out.write(result) … … 712 719 depth = min(len(fullmatch.group('hdepth')), 5) 713 720 heading = match[depth + 1:len(match) - depth - 1] 714 721 anchor = self._anchors[-1] 715 text = wiki_to_oneliner(util.unescape(heading), self.env, self.db, 716 self._absurls) 722 text = wiki_to_oneliner(heading, self.env, self.db, self._absurls) 717 723 text = re.sub(r'</?a(?: .*?)?>', '', text) # Strip out link tags 718 724 self.outline.append((depth, '<a href="#%s">%s</a>' % (anchor, text))) 719 725
