Bug 57508 - dos2unix erroneously strips \r
Summary: dos2unix erroneously strips \r
Alias: None
Product: Fedora
Classification: Fedora
Component: dos2unix
Version: rawhide
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Tim Waugh
QA Contact: Aaron Brown
Depends On:
Blocks: FC3Target FC3BugWeekTracker 183629
TreeView+ depends on / blocked
Reported: 2001-12-14 17:32 UTC by Tom Tromey
Modified: 2014-08-11 05:46 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2005-05-20 00:35:31 UTC
Type: ---

Attachments (Terms of Use)
a patch (3.06 KB, patch)
2004-09-26 09:16 UTC, Michael Schwendt
no flags Details | Diff
patch (with uneeded lines dropped) (2.50 KB, patch)
2004-09-26 09:47 UTC, Michael Schwendt
no flags Details | Diff
final patch (2.18 KB, patch)
2004-09-26 19:03 UTC, Michael Schwendt
no flags Details | Diff

System ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2005:195 low SHIPPED_LIVE dos2unix and unix2dos bug fix update 2005-05-19 04:00:00 UTC

Description Tom Tromey 2001-12-14 17:32:10 UTC
Description of Problem:

If you give dos2unix a mac file (one where lines are separate by \r alone)
and accidentally ask it to convert in DOS mode, you get a file with no

To me this seems like confusing behavior.  I'd prefer it if DOS conversion
mode changed `\r\n' to `\n' -- and left lone `\r's unmodified.  That
would reduce the potential for error.

Version-Release number of selected component (if applicable):

dos2unix 3.1 (Thu Nov 19 1998)

How Reproducible:

Steps to Reproduce:

Actual Results:

Expected Results:

Additional Information:

Comment 1 Michael Schwendt 2004-09-26 09:16:44 UTC
Created attachment 104332 [details]
a patch

Comment 2 Michael Schwendt 2004-09-26 09:47:31 UTC
Created attachment 104333 [details]
patch (with uneeded lines dropped)

My post to fedora-patch-list bounced, and when I looked at the message, I've
noticed lines in the patch which I should have deleted earlier.

Comment 3 Rik van Riel 2004-09-26 14:05:53 UTC
The patch makes sense.  I haven't been able to test it because I have
no mac files here, but the code looks sane.

Mike, want to rebuild the package or should I rebuild it ?

Comment 4 Michael Schwendt 2004-09-26 18:37:29 UTC
cat unixfile | tr \\n \\r > macfile

Comment 5 Michael Schwendt 2004-09-26 19:03:08 UTC
Created attachment 104335 [details]
final patch

While the unneeded lines in the first patch did no harm (a cut'n'rename
mistake), the second patch lost the line delimiter of the last line when
running mac2unix on a Mac file. A minor detail, easily overlooked when running

$ cd /tmp
$ cat /etc/services | tr \\n \\r > macfile
$ ls -la macfile
-rw-------  1 misc2 misc2 19936 Sep 26 21:05 macfile
$ dos2unix -c Mac macfile
dos2unix: converting file macfile to UNIX format ...
$ ls -la macfile
-rw-------  1 misc2 misc2 19936 Sep 26 21:06 macfile
$ cat macfile | tr \\r \\n > unixfile
$ md5sum unixfile /etc/services
485eacadb2a1d18fcf66483f81829f02  unixfile
485eacadb2a1d18fcf66483f81829f02  /etc/services

[size and checksum stay the same]

Comment 6 Rik van Riel 2004-09-26 21:19:00 UTC
Patch applied in dos2unix-3.1-19

Comment 7 Tim Powers 2005-05-20 00:35:31 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.


Note You need to log in before you can comment on or make changes to this bug.