comparison test/test_templating.py @ 6336:6f89cdc7c938

issue2551108 - fix markdown formatted designator links Designators like 'issue1' are automatically hyperlinked. However if typed as [issue1](issue1) or [issue1](https://example.com/issue1) they get mangled. Stop that mangling.
author John Rouillard <rouilj@ieee.org>
date Fri, 12 Mar 2021 01:30:22 -0500
parents fd0bdcbc68e4
children 316c2c32dace
comparison
equal deleted inserted replaced
6335:09678e50018c 6336:6f89cdc7c938
42 42
43 from roundup.anypy.strings import u2s, s2u 43 from roundup.anypy.strings import u2s, s2u
44 44
45 class MockDatabase(MockNull): 45 class MockDatabase(MockNull):
46 def getclass(self, name): 46 def getclass(self, name):
47 # Class returned must have hasnode(id) method that returns true
48 # otherwise designators like 'issue1' can't be hyperlinked.
49 self.classes[name].hasnode = lambda id: True
47 return self.classes[name] 50 return self.classes[name]
48 51
49 # setup for csrf testing of otks database api 52 # setup for csrf testing of otks database api
50 storage = {} 53 storage = {}
51 def set(self, key, **props): 54 def set(self, key, **props):
466 469
467 def test_string_markdown_link(self): 470 def test_string_markdown_link(self):
468 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A link <http://localhost>')) 471 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A link <http://localhost>'))
469 self.assertEqual(p.markdown().strip(), u2s(u'<p>A link <a href="http://localhost">http://localhost</a></p>')) 472 self.assertEqual(p.markdown().strip(), u2s(u'<p>A link <a href="http://localhost">http://localhost</a></p>'))
470 473
474 def test_string_markdown_link_item(self):
475 """ The link formats for the different markdown engines changes.
476 Order of attributes, value for rel (noopener, nofollow etc)
477 is different. So most tests check for a substring that indicates
478 success rather than the entire returned string.
479 """
480 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An issue1 link'))
481 self.assertIn( u2s(u'href="issue1"'), p.markdown().strip())
482 # just verify that plain linking is working
483 self.assertIn( u2s(u'href="issue1"'), p.plain(hyperlink=1))
484
485 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An [issue1](issue1) link'))
486 self.assertIn( u2s(u'href="issue1"'), p.markdown().strip())
487 # just verify that plain linking is working
488 self.assertIn( u2s(u'href="issue1"'), p.plain(hyperlink=1))
489
490 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An [issue1](https://example.com/issue1) link'))
491 self.assertIn( u2s(u'href="https://example.com/issue1"'), p.markdown().strip())
492
493 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'An [issue1] (https://example.com/issue1) link'))
494 self.assertIn( u2s(u'href="issue1"'), p.markdown().strip())
495 if type(self) == MistuneTestCase:
496 # mistune makes the https url into a real link
497 self.assertIn( u2s(u'href="https://example.com/issue1"'), p.markdown().strip())
498 else:
499 # the other two engines leave the parenthesized url as is.
500 self.assertIn( u2s(u' (https://example.com/issue1) link'), p.markdown().strip())
501
471 def test_string_markdown_link(self): 502 def test_string_markdown_link(self):
472 # markdown2 and markdown escape the email address 503 # markdown2 and markdown escape the email address
473 try: 504 try:
474 from html import unescape as html_unescape 505 from html import unescape as html_unescape
475 except ImportError: 506 except ImportError:

Roundup Issue Tracker: http://roundup-tracker.org/