Permalink
Browse files

Fix auto-recognized issue/revision links displayed in the tracker log.

These would point outside of the tracker.  Now we pass
the absolute url of the tracker.  Note that responses cache their
rendered html text in a variable ``rendered_text``, which is only
updated when you edit the response, so this may not have effect on
existing responses.
  • Loading branch information...
1 parent a5df1ca commit fe23d79e0d5828b5b9425431ff84d37e6359b36e @mauritsvanrees mauritsvanrees committed Oct 18, 2013
View
@@ -5,6 +5,15 @@ Changelog for Poi
2.2.6 (unreleased)
------------------
+- Fix auto-recognized issue/revision links when displayed in the
+ tracker log. These would point outside of the tracker. Now we pass
+ the absolute url of the tracker. Note that responses cache their
+ rendered html text in a variable ``rendered_text``, which is only
+ updated when you edit the response, so this may not have effect on
+ existing responses.
+ Fixes http://plone.org/products/poi/issues/255
+ [maurits]
+
- Fix corner cases in recognizing links to issues and revisions. Add
the patterns for these two in ``config.py`` so they can be
overridden. Also add the template to use when recognizing a link to
View
@@ -25,4 +25,4 @@
REVISION_RECOGNITION_PATTERNS = \
[r'\br[0-9]+\b', r'\bchangeset:[0-9]+\b', r'\B\[[0-9]+\]\B']
# Template to use when recognizing a link to another issue:
-ISSUE_LINK_TEMPLATE = '<a href="../%(bug)s">%(linktext)s</a>'
+ISSUE_LINK_TEMPLATE = '<a href="%(base_url)s/%(bug)s">%(linktext)s</a>'
@@ -323,7 +323,8 @@ def linkDetection(self, text):
issuefolder = self.restrictedTraverse('@@issuefolder')
issues = catalog.searchResults(issuefolder.buildIssueSearchQuery(None))
ids = frozenset([issue.id for issue in issues])
- text = linkBugs(text, ids, ISSUE_RECOGNITION_PATTERNS)
+ text = linkBugs(text, ids, ISSUE_RECOGNITION_PATTERNS,
+ base_url=self.absolute_url())
svnUrl = self.getSvnUrl()
text = linkSvn(text, svnUrl, REVISION_RECOGNITION_PATTERNS)
return text
@@ -91,6 +91,14 @@ Now we test this with patterns::
>>> linkBugs("noticket:5 ticket:5", ['5'], patterns)
'noticket:5 <a href="../5">ticket:5</a>'
+You can pass a base_url to linkBugs. The default is '..'. This works
+fine when you view an issue. But in 'tracker/@@log' such a url will
+point outside of the tracker. So now we pass the url of the tracker
+when we call the relevant code.
+
+ >>> linkBugs("#1", ['1'], patterns, base_url='http://example.org/issues')
+ '<a href="http://example.org/issues/1">#1</a>'
+
linkSvn
~~~~~~~~
@@ -564,7 +564,7 @@ def testLinksInIssues(self):
# Link to that existing issue.
issue = self.createIssue(self.tracker, details="#1")
self.assertEqual(issue.getTaggedDetails(),
- '<p><a href="../1">#1</a></p>')
+ '<p><a href="http://nohost/plone/Members/test_user_1_/issue-tracker/1">#1</a></p>')
# Issue #3 does not exist.
issue.update(details="#3")
@@ -574,7 +574,7 @@ def testLinksInIssues(self):
# Link to an existing issue in the steps
issue.update(steps="#1")
self.assertEqual(self.tracker['2'].getTaggedSteps(),
- '<p><a href="../1">#1</a></p>')
+ '<p><a href="http://nohost/plone/Members/test_user_1_/issue-tracker/1">#1</a></p>')
def testLinksToIssues(self):
tracker = self.tracker
@@ -602,15 +602,15 @@ def testLinksToIssues(self):
# Now we should get html back when we ask for an issue number:
self.assertEqual(
tracker.linkDetection("#1"),
- '<a href="../1">#1</a>')
+ '<a href="http://nohost/plone/Members/test_user_1_/issue-tracker/1">#1</a>')
self.assertEqual(
tracker.linkDetection("Links to #1 and #2."),
- 'Links to <a href="../1">#1</a> and <a href="../2">#2</a>.')
+ 'Links to <a href="http://nohost/plone/Members/test_user_1_/issue-tracker/1">#1</a> and <a href="http://nohost/plone/Members/test_user_1_/issue-tracker/2">#2</a>.')
# We are not fooled by a non existing issue:
self.assertEqual(
tracker.linkDetection("Issue #1 and non-issue #3."),
- 'Issue <a href="../1">#1</a> and non-issue #3.')
+ 'Issue <a href="http://nohost/plone/Members/test_user_1_/issue-tracker/1">#1</a> and non-issue #3.')
# Issues that are added to a different tracker only show up
# for that tracker:
@@ -621,12 +621,12 @@ def testLinksToIssues(self):
self.createIssue(tracker2, title="1")
self.assertEqual(
tracker2.linkDetection("#1"),
- '<a href="../1">#1</a>')
+ '<a href="http://nohost/plone/Members/test_user_1_/tracker2/1">#1</a>')
#A combination of unicode and a link number should be possible::
self.assertEqual(
tracker.linkDetection(u'\xfanicode text with a link to #1'),
- u'\xfanicode text with a link to <a href="../1">#1</a>')
+ u'\xfanicode text with a link to <a href="http://nohost/plone/Members/test_user_1_/issue-tracker/1">#1</a>')
def testLinksToRevisions(self):
tracker = self.tracker
@@ -671,7 +671,7 @@ def testLinksToRevisions(self):
self.createIssue(tracker, title="1")
self.assertEqual(
tracker.linkDetection('Issue #1 is fixed in r42.'),
- 'Issue <a href="../1">#1</a> is fixed in <'
+ 'Issue <a href="http://nohost/plone/Members/test_user_1_/issue-tracker/1">#1</a> is fixed in <'
'a href="http://dev.plone.org/changeset/42/collective">r42</a>.')
View
@@ -15,7 +15,7 @@ def getNumberFromString(linktext):
return linktext[res.start(): res.end()]
-def linkBugs(text, ids, patterns):
+def linkBugs(text, ids, patterns, base_url='..'):
"""
Replace patterns with links to other issues in the same tracker.
"""
@@ -32,7 +32,7 @@ def linkBugs(text, ids, patterns):
bug = getNumberFromString(linktext)
if bug is not None and bug in ids:
- link = ISSUE_LINK_TEMPLATE % dict(bug=bug, linktext=linktext)
+ link = ISSUE_LINK_TEMPLATE % dict(base_url=base_url, bug=bug, linktext=linktext)
text = text[0:pos] + link + text[res.end():]
pos += len(link)
else:

0 comments on commit fe23d79

Please sign in to comment.