Scour emits Unix-style line-ends on all platforms

Bug #482215 reported by Rob Russell
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Scour
Won't Fix
Low
Unassigned

Bug Description

On Windows, I created a file with Inkscape & saved. Opened in a text editor and the file has cr-lf (Windows-style) line endings.

Then I returned to Inkscape and saved as Optimized SVG (which runs it through Scour). Opening the new file in a text editor, the line endings are now Unix-style (lf only).

Revision history for this message
codedread (codedread) wrote :

Fixed in r155. Will be available in 0.23 of scour.

Changed in scour:
status: New → Fix Committed
codedread (codedread)
Changed in scour:
status: Fix Committed → Fix Released
Revision history for this message
Jan Thor (jan-janthor) wrote :

When I run scour from the command line (or call it from another Python script) under Windows, the line endings become \r\r\n (that is, CR-CR-LF), which appear as additional blank lines in some text editors and is obviously wrong.

I think the cause is this:

Scour produces a giant string with os.linesep as line separator, which happens to be '\r\n' under Windows, but Python internally uses \n as line separator, and, when writing a file to disk in text mode, magically replaces \n with \r\n, which turns \r\n into \r\r\n. A simple fix would be to use '\n' instead of os.linesep within the function scourString (os.linesep appears three times within this function, and another three times within serializeXML, each occurrence should simply be replaced with '\n').

Another possibility would be to prevent Python from doing its magic replacement by replacing the line

    outfile = maybe_gziped_file(options.outfilename, "w")

in parse_args with

    outfile = maybe_gziped_file(options.outfilename, "wb")

Personally, I prefer SVG files with just \n (=LF, the Unix convention) as the line ending, even under Windows, since its shorter and my text editor handles it well, so I applied *both* changes to my own copy of scour. As far as I'm aware, the current version of Inkscape also saves (non-scoured) SVG files with just \n under Windows.

Revision history for this message
Louis Simard (louis-simard-deactivatedaccount) wrote :

@Jan Thor, comment #2:

This bug report is about an issue opposite of yours. Please open another bug report for your issue.

Revision history for this message
Louis Simard (louis-simard-deactivatedaccount) wrote :

This bug reappeared after a patch for bug 717826, 'Scour emits CR CR LF for newlines on Inkscape/Windows'. Now, Scour emits Unix-style line endings (LF) on Windows, except if it's used within Inkscape, where it emits CR LF.

The nature of this bug and bug 717826 makes it hard to fix both at the same time, because they're opposites. I'm of the opinion that this bug is less important, because CR CR LF can actually cause a second newline to be appended in <text> elements after every line, giving the appearance of double spacing, but having LF on all platforms doesn't matter because of SVG's whitespace rules in xml:space="preserve" mode.

Revision history for this message
Louis Simard (louis-simard-deactivatedaccount) wrote :

This bug is now opened for comments again. If you're commenting, please explain why having LF on Windows is a bad choice compared to having CR LF.

Changed in scour:
importance: Undecided → Low
status: Fix Released → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.