mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-12 06:06:53 -05:00
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 <ludo@gnu.org>
This commit is contained in:
parent
c050f18700
commit
3149c00264
2 changed files with 9 additions and 3 deletions
|
@ -718,7 +718,7 @@ (define (absolute target)
|
||||||
|
|
||||||
(define (canonical-newline-port port)
|
(define (canonical-newline-port port)
|
||||||
"Return an input port that wraps PORT such that all newlines consist
|
"Return an input port that wraps PORT such that all newlines consist
|
||||||
of a single carriage return."
|
of a single linefeed."
|
||||||
(define (get-position)
|
(define (get-position)
|
||||||
(if (port-has-port-position? port) (port-position port) #f))
|
(if (port-has-port-position? port) (port-position port) #f))
|
||||||
(define (set-position! position)
|
(define (set-position! position)
|
||||||
|
@ -730,11 +730,11 @@ (define (read! bv start n)
|
||||||
(let loop ((count 0)
|
(let loop ((count 0)
|
||||||
(byte (get-u8 port)))
|
(byte (get-u8 port)))
|
||||||
(cond ((eof-object? byte) count)
|
(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))
|
((= count (- n 1))
|
||||||
(bytevector-u8-set! bv (+ start count) byte)
|
(bytevector-u8-set! bv (+ start count) byte)
|
||||||
n)
|
n)
|
||||||
;; XXX: consume all LFs even if not followed by CR.
|
|
||||||
((eqv? byte (char->integer #\return)) (loop count (get-u8 port)))
|
|
||||||
(else
|
(else
|
||||||
(bytevector-u8-set! bv (+ start count) byte)
|
(bytevector-u8-set! bv (+ start count) byte)
|
||||||
(loop (+ count 1) (get-u8 port))))))
|
(loop (+ count 1) (get-u8 port))))))
|
||||||
|
|
|
@ -230,6 +230,12 @@ (define (test-compression/decompression method run?)
|
||||||
"This is a journey\r\nInto the sound\r\nA journey ...\n")))
|
"This is a journey\r\nInto the sound\r\nA journey ...\n")))
|
||||||
(get-string-all (canonical-newline-port port))))
|
(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"
|
(test-equal "edit-expression"
|
||||||
"(display \"GNU Guix\")\n(newline)\n"
|
"(display \"GNU Guix\")\n(newline)\n"
|
||||||
|
|
Loading…
Reference in a new issue