guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

02/03: utils: canonical-newline-port: Fix handling of carriage return at


From: guix-commits
Subject: 02/03: utils: canonical-newline-port: Fix handling of carriage return at buffer end.
Date: Thu, 20 Jun 2019 08:07:12 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 3149c002644b927e0245d237cdda3a6aeca00e4a
Author: Robert Vollmert <address@hidden>
Date:   Sun Jun 16 16:18:29 2019 +0200

    utils: canonical-newline-port: Fix handling of carriage return at buffer 
end.
    
    Prior to this change the added test fails for me locally at byte
    1024. It might depend on some default buffer sizes.
    
    Fixes <https://bugs.gnu.org/35863>.
    
    * tests/utils.scm ("canonical-newline-port-1024"): Add test.
    * guix/utils.scm (canonical-newline-port): Correct comments on CR/LF.
    Remove CR even when they're at the end of the buffer.
    
    Signed-off-by: Ludovic Courtès <address@hidden>
---
 guix/utils.scm  | 6 +++---
 tests/utils.scm | 6 ++++++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/guix/utils.scm b/guix/utils.scm
index 709cdf9..f480c32 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -718,7 +718,7 @@ environment variable name like \"XDG_CONFIG_HOME\"; SUFFIX 
is a suffix like
 
 (define (canonical-newline-port port)
   "Return an input port that wraps PORT such that all newlines consist
-  of a single carriage return."
+  of a single linefeed."
   (define (get-position)
     (if (port-has-port-position? port) (port-position port) #f))
   (define (set-position! position)
@@ -730,11 +730,11 @@ environment variable name like \"XDG_CONFIG_HOME\"; 
SUFFIX is a suffix like
     (let loop ((count 0)
                (byte (get-u8 port)))
       (cond ((eof-object? byte) count)
+            ;; XXX: consume all CRs even if not followed by LF.
+            ((eqv? byte (char->integer #\return)) (loop count (get-u8 port)))
             ((= count (- n 1))
              (bytevector-u8-set! bv (+ start count) byte)
              n)
-            ;; XXX: consume all LFs even if not followed by CR.
-            ((eqv? byte (char->integer #\return)) (loop count (get-u8 port)))
             (else
              (bytevector-u8-set! bv (+ start count) byte)
              (loop (+ count 1) (get-u8 port))))))
diff --git a/tests/utils.scm b/tests/utils.scm
index 4486138..f78ec35 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -230,6 +230,12 @@ skip these tests."
                "This is a journey\r\nInto the sound\r\nA journey ...\n")))
     (get-string-all (canonical-newline-port port))))
 
+(test-equal "canonical-newline-port-1024"
+  (string-concatenate (make-list 100 "0123456789abcde\n"))
+  (let ((port (open-string-input-port
+               (string-concatenate
+                (make-list 100 "0123456789abcde\r\n")))))
+    (get-string-all (canonical-newline-port port))))
 
 (test-equal "edit-expression"
   "(display \"GNU Guix\")\n(newline)\n"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]