From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:34195) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hcW2l-0008JL-On for guix-patches@gnu.org; Sun, 16 Jun 2019 10:22:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hcW2k-0005ZG-Cf for guix-patches@gnu.org; Sun, 16 Jun 2019 10:22:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55911) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hcW2k-0005ZC-9n for guix-patches@gnu.org; Sun, 16 Jun 2019 10:22:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hcW2k-0000EW-5E for guix-patches@gnu.org; Sun, 16 Jun 2019 10:22:02 -0400 Subject: [bug#36244] [PATCH] guix: canonical-newline-port: Fix handling of carriage return at buffer end. Resent-Message-ID: Received: from eggs.gnu.org ([2001:470:142:3::10]:34078) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hcW2f-0008CP-3x for guix-patches@gnu.org; Sun, 16 Jun 2019 10:21:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hcVzb-0003Ih-P8 for guix-patches@gnu.org; Sun, 16 Jun 2019 10:18:49 -0400 Received: from mx1.mailbox.org ([80.241.60.212]:17646) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hcVzb-0003G4-JG for guix-patches@gnu.org; Sun, 16 Jun 2019 10:18:47 -0400 From: Robert Vollmert Date: Sun, 16 Jun 2019 16:18:29 +0200 Message-Id: <20190616141829.28689-1-rob@vllmrt.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 36244@debbugs.gnu.org Cc: Robert Vollmert 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=3D35863 * 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\"; S= UFFIX is a suffix like =20 (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 po= rt))) ((=3D 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 po= rt))) (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)))) =20 +(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)))) =20 (test-equal "edit-expression" "(display \"GNU Guix\")\n(newline)\n" --=20 2.20.1 (Apple Git-117)