Edgewall Software

Opened 4 years ago

Closed 3 years ago

#569 closed defect (fixed)

Suppressing linebreaks with backspaces dosen't work in 0.7

Reported by: anonymous Owned by: hodgestar
Priority: major Milestone: 0.7
Component: General Version:
Keywords: Cc:



Using Genshi 0.6 (with speedups) + Trac 1.0.1 generates emails looking like http://trac.edgewall.org/wiki/TracNotification#SampleEmail

But using Genshi 0.7 (with speedups) results in all "\" being showed in the email and no linebreaks are removed.

Or are the docs outdated? http://genshi.edgewall.org/wiki/Documentation/text-templates.html#white-space-and-line-breaks

Attachments (1)

suppress-linebreaks-with-crlf.patch (1.8 KB) - added by t2y <tetsuya.morimoto@…> 3 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 4 years ago by hodgestar

This sounds like a regression in 0.7.

comment:2 Changed 4 years ago by hodgestar

There are tests for this in 0.7 and they appear to pass. Could you provide a short example showing the problem?

comment:3 Changed 4 years ago by anonymous

This is what Trac uses:

{% choose ticket.new %}\
{%   when True %}\
{%   end %}\
{%   otherwise %}\
{%     if changes_body %}\
${_('Changes (by %(author)s):', author=change.author)}

{%     end %}\
{%     if changes_descr %}\
{%       if not changes_body and not change.comment and change.author %}\
${_('Description changed by %(author)s:', author=change.author)}
{%       end %}\
{%     end %}\
{%     if change.comment %}\

${_('Comment:') if changes_body else _('Comment (by %(author)s):', author=change.author)}

{%     end %}\
{%   end %}\
{% end %}\

${_('Ticket URL: <%(link)s>', link=ticket.link)}
$project.name <${project.url or abs_href()}>

Which can be found here: http://trac.edgewall.org/browser/tags/trac-1.0.1/trac/ticket/templates/ticket_notify_email.txt

comment:4 follow-up: Changed 4 years ago by hodgestar

This bit of Python code works fine for me on 0.7:

>>> t = """$ticket_body_hdr
... $ticket_props
... {% choose ticket.new %}\
... {%   when True %}\
... $ticket.description
... {%   end %}\
... {% end %}\
... """
>>> tmpl = NewTextTemplate(t)
>>> class Ticket(object):
...    pass
>>> ticket = Ticket()
>>> ticket.new = True
>>> ticket.description = "Description"
>>> tmpl.generate(ticket_body_hdr="HDR", ticket_props="PROPS", ticket=ticket).render()

Does it work for you?

comment:5 Changed 4 years ago by hodgestar

My example is missing a

>>> from genshi.template.text import NewTextTemplate

at the top.

comment:6 Changed 4 years ago by hodgestar

  • Owner changed from cmlenz to hodgestar
  • Status changed from new to assigned

comment:7 in reply to: ↑ 4 ; follow-up: Changed 4 years ago by jomae

Replying to hodgestar:

>>> t = """$ticket_body_hdr..."""

The multiline strings don't have \-escape at end of line.

>>> t = """aaaaa
... bbbbbb\
... ccccc"""
>>> print t

The test cases in genshi/templates/tests/text.py have the same.

comment:8 in reply to: ↑ 7 Changed 4 years ago by hodgestar

Replying to jomae:

The multiline strings don't have \-escape at end of line.

Oops. You are correct. I will fix the tests.

Adding t = r""" doesn't change the result though, so the newline escaping is working.

comment:9 Changed 4 years ago by hodgestar

It turns out this is caused by a combination of Genshi changing from loading templates with file mode "U" to opening them with file mode "rb" in 0.7, and of this particular Trac template having "\r\n" line-endings.

comment:10 Changed 3 years ago by t2y <tetsuya.morimoto@…>

Is this difficult to fix? or is there any workaround?

comment:11 Changed 3 years ago by t2y <tetsuya.morimoto@…>

Then, I finally understood. This issue happens when the template has \r\n line break. I can accept to avoid extra \ character using only \n for the template. However, in case the email-template, RFC says \r\n (CRLF) is appropriate as line break.

http://tools.ietf.org/html/rfc2046#section-4.1.1 http://tools.ietf.org/html/rfc2822

Changed 3 years ago by t2y <tetsuya.morimoto@…>

comment:12 Changed 3 years ago by t2y <tetsuya.morimoto@…>

I made a simple patch for trunk (0.8dev) to be able to handle CRLF line break. I confirmed all tests are passed on py26, py27, py32, py33. Could you review it?


comment:13 Changed 3 years ago by hodgestar

  • Resolution set to fixed
  • Status changed from assigned to closed

Thanks for the patch! Applied to trunk in r1255 and to 0.7.x in r1256.

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain hodgestar.
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.