Hi Mark! Mark H Weaver <m...@netris.org> skribis:
> l...@gnu.org (Ludovic Courtès) writes: > >> Eli Zaretskii <e...@gnu.org> skribis: >> >>> It's due to the CRLF thing. These files are open in the "w" mode, but >>> then read using the "rb" mode. So the CR character is left after the >>> newline is stripped, and botches the comparison. The debug lines you >>> added show this (note the \r at the end): >>> >>> ;;; (line "\xe4\xb8\x80\xe4\xba\x8c\xe4\xb8\x89\r") >>> FAIL: ports.test: file: binary mode ignores port encoding >>> >>> ;;; (line2 "\xe4\xb8\x80\xe4\xba\x8c\xe4\xb8\x89\r") >>> FAIL: ports.test: file: binary mode ignores file coding declaration >> >> I think this patch solves the problem: >> >> diff --git a/libguile/rdelim.c b/libguile/rdelim.c >> index 9d14967..9f16c69 100644 >> --- a/libguile/rdelim.c >> +++ b/libguile/rdelim.c >> @@ -154,6 +154,7 @@ SCM_DEFINE (scm_read_line, "%read-line", 0, 1, 0, >> { >> case EOF: >> case '\n': >> + case '\r': >> delim = buf[index]; >> break; >> >> >> Probably the extra case should be #ifdef __MINGW32__, to make sure it >> has no effect on non-Windows users. Thoughts? > > I think this is a bad idea for multiple reasons: Well yes, agreed on all points. I think now we just need to augments ports with CR/LF handling in 2.1. [...] > To my mind, this is a bug in those tests. So how about the following > patch instead? [...] > diff --git a/test-suite/tests/ports.test b/test-suite/tests/ports.test > index 9b1c6c0..758f8f6 100644 > --- a/test-suite/tests/ports.test > +++ b/test-suite/tests/ports.test > @@ -238,7 +238,7 @@ > (pass-if "file: binary mode ignores port encoding" > (with-fluids ((%default-port-encoding "UTF-8")) > (let* ((filename (test-file)) > - (port (open-file filename "w")) > + (port (open-file filename "wb")) > (test-string "一二三") > (binary-test-string > (apply string > @@ -257,7 +257,7 @@ > (pass-if "file: binary mode ignores file coding declaration" > (with-fluids ((%default-port-encoding "UTF-8")) > (let* ((filename (test-file)) > - (port (open-file filename "w")) > + (port (open-file filename "wb")) > (test-string "一二三") > (binary-test-string > (apply string Yes, looks good. The tests would actually make more sense if %default-port-encoding was set to something different from UTF-8, because here we can’t tell if it’s ignored. Thanks, Ludo’.