##// END OF EJS Templates
emails: fixed newlines in email templates that can break email sending code.
marcink -
r1728:49fb0cec default
parent child Browse files
Show More
@@ -332,14 +332,19 b' class EmailNotificationModel(BaseModel):'
332
332
333 :param kwargs:
333 :param kwargs:
334 """
334 """
335
335 kwargs['rhodecode_instance_name'] = self.rhodecode_instance_name
336 kwargs['rhodecode_instance_name'] = self.rhodecode_instance_name
336
337
337 _kwargs = {
338 _kwargs = {
338 'instance_url': h.url('home', qualified=True),
339 'instance_url': h.url('home', qualified=True),
340 'whitespace_filter': self.whitespace_filter
339 }
341 }
340 _kwargs.update(kwargs)
342 _kwargs.update(kwargs)
341 return _kwargs
343 return _kwargs
342
344
345 def whitespace_filter(self, text):
346 return text.replace('\n', '').replace('\t', '')
347
343 def get_renderer(self, type_):
348 def get_renderer(self, type_):
344 template_name = self.email_types[type_]
349 template_name = self.email_types[type_]
345 return PartialRenderer(template_name)
350 return PartialRenderer(template_name)
@@ -3,7 +3,7 b''
3 <%namespace name="base" file="base.mako"/>
3 <%namespace name="base" file="base.mako"/>
4
4
5 ## EMAIL SUBJECT
5 ## EMAIL SUBJECT
6 <%def name="subject()" filter="n,trim">
6 <%def name="subject()" filter="n,trim,whitespace_filter">
7 <%
7 <%
8 data = {
8 data = {
9 'user': h.person(user),
9 'user': h.person(user),
@@ -1,7 +1,7 b''
1 ## -*- coding: utf-8 -*-
1 ## -*- coding: utf-8 -*-
2 <%inherit file="base.mako"/>
2 <%inherit file="base.mako"/>
3
3
4 <%def name="subject()" filter="n,trim">
4 <%def name="subject()" filter="n,trim,whitespace_filter">
5 RhodeCode test email: ${h.format_date(date)}
5 RhodeCode test email: ${h.format_date(date)}
6 </%def>
6 </%def>
7
7
@@ -1,7 +1,7 b''
1 ## -*- coding: utf-8 -*-
1 ## -*- coding: utf-8 -*-
2 <%inherit file="base.mako"/>
2 <%inherit file="base.mako"/>
3
3
4 <%def name="subject()" filter="n,trim">
4 <%def name="subject()" filter="n,trim,whitespace_filter">
5 </%def>
5 </%def>
6
6
7
7
@@ -1,7 +1,7 b''
1 ## -*- coding: utf-8 -*-
1 ## -*- coding: utf-8 -*-
2 <%inherit file="base.mako"/>
2 <%inherit file="base.mako"/>
3
3
4 <%def name="subject()" filter="n,trim">
4 <%def name="subject()" filter="n,trim,whitespace_filter">
5 RhodeCode Password reset
5 RhodeCode Password reset
6 </%def>
6 </%def>
7
7
@@ -1,7 +1,7 b''
1 ## -*- coding: utf-8 -*-
1 ## -*- coding: utf-8 -*-
2 <%inherit file="base.mako"/>
2 <%inherit file="base.mako"/>
3
3
4 <%def name="subject()" filter="n,trim">
4 <%def name="subject()" filter="n,trim,whitespace_filter">
5 Your new RhodeCode password
5 Your new RhodeCode password
6 </%def>
6 </%def>
7
7
@@ -3,7 +3,7 b''
3 <%namespace name="base" file="base.mako"/>
3 <%namespace name="base" file="base.mako"/>
4
4
5 ## EMAIL SUBJECT
5 ## EMAIL SUBJECT
6 <%def name="subject()" filter="n,trim">
6 <%def name="subject()" filter="n,trim,whitespace_filter">
7 <%
7 <%
8 data = {
8 data = {
9 'user': h.person(user),
9 'user': h.person(user),
@@ -2,7 +2,7 b''
2 <%inherit file="base.mako"/>
2 <%inherit file="base.mako"/>
3 <%namespace name="base" file="base.mako"/>
3 <%namespace name="base" file="base.mako"/>
4
4
5 <%def name="subject()" filter="n,trim">
5 <%def name="subject()" filter="n,trim,whitespace_filter">
6 <%
6 <%
7 data = {
7 data = {
8 'user': h.person(user),
8 'user': h.person(user),
@@ -1,7 +1,7 b''
1 ## -*- coding: utf-8 -*-
1 ## -*- coding: utf-8 -*-
2 <%inherit file="base.mako"/>
2 <%inherit file="base.mako"/>
3
3
4 <%def name="subject()" filter="n,trim">
4 <%def name="subject()" filter="n,trim,whitespace_filter">
5 Test "Subject" ${_('hello "world"')|n}
5 Test "Subject" ${_('hello "world"')|n}
6 </%def>
6 </%def>
7
7
@@ -1,7 +1,7 b''
1 ## -*- coding: utf-8 -*-
1 ## -*- coding: utf-8 -*-
2 <%inherit file="base.mako"/>
2 <%inherit file="base.mako"/>
3
3
4 <%def name="subject()" filter="n,trim">
4 <%def name="subject()" filter="n,trim,whitespace_filter">
5 RhodeCode new user registration: ${user.username}
5 RhodeCode new user registration: ${user.username}
6 </%def>
6 </%def>
7
7
@@ -3,6 +3,7 b' import collections'
3 import pytest
3 import pytest
4
4
5 from rhodecode.lib.utils import PartialRenderer
5 from rhodecode.lib.utils import PartialRenderer
6 from rhodecode.lib.utils2 import AttributeDict
6 from rhodecode.model.notification import EmailNotificationModel
7 from rhodecode.model.notification import EmailNotificationModel
7
8
8
9
@@ -66,3 +67,57 b' def test_render_pr_email(pylonsapp, user'
66
67
67 # subject
68 # subject
68 assert subject == 'Marcin Kuzminski wants you to review pull request #200: "Example Pull Request"'
69 assert subject == 'Marcin Kuzminski wants you to review pull request #200: "Example Pull Request"'
70
71
72 @pytest.mark.parametrize('mention', [
73 True,
74 False
75 ])
76 @pytest.mark.parametrize('email_type', [
77 EmailNotificationModel.TYPE_COMMIT_COMMENT,
78 EmailNotificationModel.TYPE_PULL_REQUEST_COMMENT
79 ])
80 def test_render_comment_subject_no_newlines(pylonsapp, mention, email_type):
81 ref = collections.namedtuple('Ref',
82 'name, type')(
83 'fxies123', 'book'
84 )
85
86 pr = collections.namedtuple('PullRequest',
87 'pull_request_id, title, description, source_ref_parts, source_ref_name, target_ref_parts, target_ref_name')(
88 200, 'Example Pull Request', 'Desc of PR', ref, 'bookmark', ref, 'Branch')
89
90 source_repo = target_repo = collections.namedtuple('Repo',
91 'type, repo_name')(
92 'hg', 'pull_request_1')
93
94 kwargs = {
95 'user': '<marcin@rhodecode.com> Marcin Kuzminski',
96 'commit': AttributeDict(raw_id='a'*40, message='Commit message'),
97 'status_change': 'approved',
98 'commit_target_repo': AttributeDict(),
99 'repo_name': 'test-repo',
100 'comment_file': 'test-file.py',
101 'comment_line': 'n100',
102 'comment_type': 'note',
103 'commit_comment_url': 'http://comment-url',
104 'instance_url': 'http://rc-instance',
105 'comment_body': 'hello world',
106 'mention': mention,
107
108 'pr_comment_url': 'http://comment-url',
109 'pr_source_repo': AttributeDict(repo_name='foobar'),
110 'pr_source_repo_url': 'http://soirce-repo/url',
111 'pull_request': pr,
112 'pull_request_commits': [],
113
114 'pull_request_target_repo': target_repo,
115 'pull_request_target_repo_url': 'x',
116
117 'pull_request_source_repo': source_repo,
118 'pull_request_source_repo_url': 'x',
119 }
120 subject, headers, body, body_plaintext = EmailNotificationModel().render_email(
121 email_type, **kwargs)
122
123 assert '\n' not in subject
General Comments 0
You need to be logged in to leave comments. Login now