Edgewall Software

Opened 11 years ago

Last modified 8 years ago

#589 new defect

Backslash newline handling in Windows regression

Reported by: anonymous Owned by: cmlenz
Priority: major Milestone: 0.9
Component: General Version: devel
Keywords: Cc:

Description

I think an issue was introduced with the following change that loads files in binary mode: http://genshi.edgewall.org/changeset/1190

I'm using a software package on Windows that had originally worked with Genshi 0.5 (before change #1190). The templates in this package has many directives followed by newlines, like so: {% directive %]\

On my mac, using Genshi 0.7, those lines are completely stripped out of the resulting output files. On my windows machine, however, those lines become a single backslash.

I think this is because the following regex in text.py:

_ESCAPE_RE = r'
\n|
(
)|
(%s)|
(%s)'

was working previously because the '
\n' was matching these lines in windows when files were opened with 'rU', but now that they're opened with 'rb', the lines have the Windows \r\n line ending.

This is the test code I'm using, with an input file

# genshi test # input file should be: # {% end %}\ # hello

from genshi.template import NewTextTemplate?, TemplateLoader? from os import path import shutil

srcfile = 'testtemplate-in.json' dstfile = 'testtemplate-out.json' loader = TemplateLoader?(path.dirname(srcfile)) tmpl = loader.load(path.basename(srcfile), cls=NewTextTemplate?) stream = tmpl.generate() tmp_file = srcfile+'-tmp' with open(tmp_file, 'w') as out_file:

out_file.write(stream.render('text'))

from_to = (tmp_file, dstfile) shutil.move(*from_to)

Change History (1)

comment:1 Changed 8 years ago by hodgestar

  • Milestone changed from 0.7 to 0.9

Moved to milestone 0.9.

Note: See TracTickets for help on using tickets.