diff --git a/core/io/encodings/encodings-tests.factor b/core/io/encodings/encodings-tests.factor index f6c94684bd..72035c988c 100644 --- a/core/io/encodings/encodings-tests.factor +++ b/core/io/encodings/encodings-tests.factor @@ -87,3 +87,15 @@ unit-test "\r\n" read-until ] with-byte-reader ] unit-test + +{ + "! lol" + "! wa" + 116 +} [ + "! lol\r\n! wat\r\n" utf8 encode + utf8 [ + readln + "t" read-until + ] with-byte-reader +] unit-test diff --git a/core/io/encodings/encodings.factor b/core/io/encodings/encodings.factor index 63538dba9e..7c13e8fce3 100644 --- a/core/io/encodings/encodings.factor +++ b/core/io/encodings/encodings.factor @@ -163,13 +163,18 @@ M: decoder stream-contents* M: decoder stream-read-until dup cr>> [ - 2dup + dup cr- 2dup >decoder< decode-until - 2dup [ empty? ] [ CHAR: \n = ] bi* and [ - 2drop stream-read-until + over [ + dup CHAR: \n = [ + 2drop stream-read-until + ] [ + [ 2drop ] 2dip + ] if ] [ - [ cr- drop ] 2dip - ] if + first-unsafe CHAR: \n = [ [ rest ] dip ] when + [ 2drop ] 2dip + ] if-empty ] [ >decoder< decode-until ] if ;