diff --git a/core/io/encodings/encodings-tests.factor b/core/io/encodings/encodings-tests.factor index cc32f30060..f6c94684bd 100644 --- a/core/io/encodings/encodings-tests.factor +++ b/core/io/encodings/encodings-tests.factor @@ -1,6 +1,7 @@ USING: accessors io io.encodings io.encodings.ascii -io.encodings.utf8 io.files io.streams.byte-array -io.streams.string kernel namespaces tools.test ; +io.encodings.string io.encodings.utf8 io.files +io.streams.byte-array io.streams.string kernel namespaces +tools.test ; IN: io.encodings.tests [ { } ] @@ -73,3 +74,16 @@ unit-test output-stream get code>> ] with-byte-writer drop ] unit-test + +! Bug 1177. +{ + "! lol" + "! wat" + 13 +} [ + "! lol\r\n! wat\r\n" utf8 encode + utf8 [ + readln + "\r\n" read-until + ] with-byte-reader +] unit-test diff --git a/core/io/encodings/encodings.factor b/core/io/encodings/encodings.factor index 2ee100dd52..63538dba9e 100644 --- a/core/io/encodings/encodings.factor +++ b/core/io/encodings/encodings.factor @@ -161,7 +161,18 @@ M: decoder stream-contents* { CHAR: \n [ line-ends\n ] } } case ; inline -M: decoder stream-read-until >decoder< decode-until ; +M: decoder stream-read-until + dup cr>> [ + 2dup + >decoder< decode-until + 2dup [ empty? ] [ CHAR: \n = ] bi* and [ + 2drop stream-read-until + ] [ + [ cr- drop ] 2dip + ] if + ] [ + >decoder< decode-until + ] if ; M: decoder stream-readln "\r\n" over >decoder< decode-until handle-readln ;