Opened 5 years ago
Closed 4 years ago
#13225 closed defect (fixed)
[notification] ticket_subject_template cannot begin with # character
Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Milestone: | 1.4.2 |
Component: | general | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: |
Fixed |
||
API Changes: | |||
Internal Changes: |
Description
Reported in th:comment:8:ticket:13654. The issue is seen with [notification] ticket_subject_template, and likely [notification] batch_subject_template.
[notification] ticket_subject_template = #${ticket.id}: ${summary}
Need to check if the issue occurs prior to the Jinja2 transition.
Attachments (0)
Change History (12)
comment:1 by , 5 years ago
Summary: | ticket_subject_template cannot begin with # character → [notification] ticket_subject_template cannot begin with # character |
---|
comment:2 by , 5 years ago
comment:3 by , 5 years ago
I think line_comment_prefix=None
should be used by the same reason.
>>> from trac.util.text import jinja2env >>> data = {'ticket': {'id': 42}} >>> def jinja2template(template, text=False): ... return jinja2env(autoescape=not text, ... line_statement_prefix=None).from_string(template) ... >>> jinja2template('${ticket.id}', text=True).render(**data) u'42' >>> >>> jinja2template('#${ticket.id}', text=True).render(**data) u'#42' >>> jinja2template('##${ticket.id}', text=True).render(**data) u'' >>> >>> def jinja2template(template, text=False): ... return jinja2env(autoescape=not text, ... line_statement_prefix=None, ... line_comment_prefix=None).from_string(template) ... >>> jinja2template('#${ticket.id}', text=True).render(**data) u'#42' >>> jinja2template('##${ticket.id}', text=True).render(**data) u'##42'
comment:4 by , 5 years ago
Milestone: | next-stable-1.4.x → 1.4.1 |
---|
comment:5 by , 5 years ago
Milestone: | 1.4.1 → 1.4.2 |
---|
comment:6 by , 5 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:7 by , 5 years ago
Release Notes: | modified (diff) |
---|
Added test coverage to anonymous comment:1 change and Jun's comment:2 change: log:rjollos.git:t13325_ticket_subject_template.
follow-up: 11 comment:8 by , 5 years ago
This could break plugins that need multiline templates with comments or statements, right? (I'm not aware of any such plugins, so maybe not a problem.)
Would a jinja2template(..., oneliner=True)
parameter be useful?
For example a (untested) Jinja2TemplateTestCase:
def test_multiline_text_template(self): self.assertEqual(""" ## This is a comment in a multiline template with the following statement: # if True: <h1>Hell&O</h1> # endif """, jinja2template("<h1>${hell}O</h1>", text=True, oneliner=False).render( {'hell': 'Hell&'}))
Or is jinja2template
inherently intended only for oneliners, and multiline templates should always use chrome.render_template_string
instead? Is it limited to text=True
?
comment:9 by , 5 years ago
It's a good question. Probably better to add the oneliner=True
option unless someone has a good answer otherwise.
comment:11 by , 4 years ago
Replying to Peter Suter:
Or is
jinja2template
inherently intended only for oneliners, and multiline templates should always usechrome.render_template_string
instead?
I think this is the right question. The notification body is rendered using text=True
but chrome.render_template_string is used.
A plugin implementing notification might use inline source for the notification body, and that inline source might have statements. The inline source code might be plain text (text=True
) or HTML (text=False
).
Instead, added a utility function in trac.ticket.notification
that avoids explicitly adding an argument to jinja2template
. Instead, jinja2template
supports pass-through of arguments to jinjaenv
: [59709a6e8/rjollos.git]
comment:12 by , 4 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
In trac.ticket.notification.TicketFormatter._format_subj and
._format_subj_batchmodify
the calls to trac.util.text.jinja2template useline_statement_prefix='#'
.The default
line_statement_prefix=None
(and similar forline_comment_prefix
) is probably better for such single-line templates.