Preserve Windows newlines
authorJamie Cameron <jcameron@webmin.com>
Sun, 14 Oct 2007 05:28:43 +0000 (05:28 +0000)
committerJamie Cameron <jcameron@webmin.com>
Sun, 14 Oct 2007 05:28:43 +0000 (05:28 +0000)
CHANGELOG
web-lib-funcs.pl

index 17f862b..53181bf 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -76,3 +76,4 @@ Fixed XSS bugs in pam_login.cgi.
 ---- Changes since 1.370 ----
 Hid the Jabber and Security Sentries modules by default, as the underlying software is no longer supported.
 On Linux systems, sped up the function for finding processes so that it no longer has to launch 'ps' - instead, it reads /proc directly.
+When read_file_lines is used to read a file, the Unix or Windows newlines will be preserved when it is written out.
index 3cfe314..cf37e71 100755 (executable)
@@ -1932,15 +1932,19 @@ if (!$_[0]) {
        }
 local $realfile = &translate_filename($_[0]);
 if (!$main::file_cache{$realfile}) {
-        local(@lines, $_);
+        local(@lines, $_, $eol);
         open(READFILE, $realfile);
         while(<READFILE>) {
+               if (!$eol) {
+                       $eol = /\r\n$/ ? "\r\n" : "\n";
+                       }
                 tr/\r\n//d;
                 push(@lines, $_);
                 }
         close(READFILE);
         $main::file_cache{$realfile} = \@lines;
        $main::file_cache_noflush{$realfile} = $_[1];
+       $main::file_cache_eol{$realfile} = $eol || "\n";
         }
 else {
        # Make read-write if currently readonly
@@ -1967,8 +1971,8 @@ if ($_[0]) {
 else {
        @files = ( keys %main::file_cache );
        }
-local $eol = $_[1] || "\n";
 foreach $f (@files) {
+       local $eol = $_[1] || $main::file_cache_eol{$f} || "\n";
        if (!$main::file_cache_noflush{$f}) {
                &open_tempfile(FLUSHFILE, ">$f");
                local $line;