From d534b3e79c89dfae2bd708d6f0575de6e7788420 Mon Sep 17 00:00:00 2001 From: Ashish Kulkarni Date: Tue, 23 Feb 2016 12:47:25 +0530 Subject: [PATCH] fix comment URL in notification email when base_url is configured When base_url is configured, abs_href() will include the path, which is again duplicated via Comment.href(). This probably works when trac is deployed at the site root but doesn't when it is at a subdirectory e.g. "/trac". fixes #47 and #62 --- code_comments/notification.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/code_comments/notification.py b/code_comments/notification.py index dded21a..f1e6031 100644 --- a/code_comments/notification.py +++ b/code_comments/notification.py @@ -1,3 +1,5 @@ +from urlparse import urlsplit + from trac.config import BoolOption from trac.core import Component, implements from trac.notification import NotifyEmail @@ -95,9 +97,15 @@ def _get_author_name(self, comment): def notify(self, comment): self.comment_author = self._get_author_name(comment) + comment_base = self.env.abs_href() + if self.env.abs_href.base: + split = urlsplit(self.env.abs_href.base) + if split.scheme and split.netloc: + comment_base = '%s://%s' % (split.scheme, split.netloc) + self.data.update({ "comment": comment, - "comment_url": self.env.abs_href() + comment.href(), + "comment_url": comment_base + comment.href(), "project_url": self.env.project_url or self.env.abs_href(), })