From cd49c2103b29fdf793506889f7ef96a133e54a05 Mon Sep 17 00:00:00 2001 From: Alvydas Vitkauskas Date: Thu, 1 Aug 2019 01:48:10 +0300 Subject: [PATCH] os: fix read_lines for win/dos files on unix --- vlib/os/os.v | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/vlib/os/os.v b/vlib/os/os.v index 06a9e0993f..36010ef924 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -190,13 +190,11 @@ pub fn read_lines(path string) []string { buf_index = len continue } - if buf[len - 1] == 10 { + if buf[len - 1] == 10 || buf[len - 1] == 13 { buf[len - 1] = `\0` } - $if windows { - if buf[len - 2] == 13 { - buf[len - 2] = `\0` - } + if len > 1 && buf[len - 2] == 13 { + buf[len - 2] = `\0` } res << tos_clone(buf) buf_index = 0