>From 45dc69c3a604ed2eb8d5831018435a7787887b33 Mon Sep 17 00:00:00 2001 From: Evan Hanson Date: Thu, 31 Oct 2013 19:05:17 +1300 Subject: [PATCH 2/2] Treat lone carriage returns as line endings in ##sys#scan-buffer-line This fixes #1004. Signed-off-by: Peter Bex --- library.scm | 2 ++ tests/port-tests.scm | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/library.scm b/library.scm index d95724a..2d6080b 100644 --- a/library.scm +++ b/library.scm @@ -3665,6 +3665,8 @@ EOF (##sys#string-append line "\r"))) ;; Restore \r here, too (when we reached EOF) (values offset (##sys#string-append line "\r") #t))))) + ((eq? c #\return) + (values (fx+ pos 1) (copy&append buf offset pos line) #t)) (else (loop buf offset (fx+ pos 1) limit line)) ) ) ) ) ) (define (open-input-string string) diff --git a/tests/port-tests.scm b/tests/port-tests.scm index ebba350..259892c 100644 --- a/tests/port-tests.scm +++ b/tests/port-tests.scm @@ -353,6 +353,27 @@ EOF buf "89067"))) +(test-group "line endings" + (let ((s "foo\nbar\rbaz\r\nqux") + (f (lambda () + (test-equal "\\n" (read-line) "foo") + (test-equal "\\r" (read-line) "bar") + (test-equal "\\r\\n" (read-line) "baz") + (test-equal "eof" (read-line) "qux")))) + (test-group "string port" + (with-input-from-string s f)) + (test-group "file port" + (let ((file "mixed-line-endings")) + (with-output-to-file file (lambda () (display s))) + (with-input-from-file file f) + (delete-file* file))) + (test-group "custom port" + (let* ((p (open-input-string s)) + (p* (make-input-port (lambda () (read-char p)) + (lambda () (char-ready? p)) + (lambda () (close-input-port p))))) + (with-input-from-port p* f))))) + ;; Disabled because it requires `echo -n` for ;; the EOF test, and that is not available on all systems. ;; Uncomment locally to run. -- 1.8.3.4