unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Robert Vollmert <rob@vllmrt.net>
To: 36244@debbugs.gnu.org
Cc: Robert Vollmert <rob@vllmrt.net>
Subject: [bug#36244] [PATCH] guix: canonical-newline-port: Fix handling of carriage return at buffer end.
Date: Sun, 16 Jun 2019 16:18:29 +0200	[thread overview]
Message-ID: <20190616141829.28689-1-rob@vllmrt.net> (raw)

Prior to this change the added test fails for me locally at byte
1024. It might depend on some default buffer sizes.

Fixes https://debbugs.gnu.org/cgi/bugreport.cgi?bug=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.
---
 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 709cdf9353..f480c3291f 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 44861384ab..f78ec356bd 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"
-- 
2.20.1 (Apple Git-117)

             reply	other threads:[~2019-06-16 14:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-16 14:18 Robert Vollmert [this message]
2019-06-20 11:59 ` bug#36244: [PATCH] guix: canonical-newline-port: Fix handling of carriage return at buffer end Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190616141829.28689-1-rob@vllmrt.net \
    --to=rob@vllmrt.net \
    --cc=36244@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).