Skip to content

Commit

Permalink
feat: handle \r on all operating systems in IO.FS.lines (#4973)
Browse files Browse the repository at this point in the history
Closes: #4573
  • Loading branch information
hargoniX authored Aug 12, 2024
1 parent 5c182bd commit da9d44d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Init/System/IO.lean
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ partial def lines (fname : FilePath) : IO (Array String) := do
pure lines
else if line.back == '\n' then
let line := line.dropRight 1
let line := if System.Platform.isWindows && line.back == '\x0d' then line.dropRight 1 else line
let line := if line.back == '\r' then line.dropRight 1 else line
read <| lines.push line
else
pure <| lines.push line
Expand Down
12 changes: 12 additions & 0 deletions tests/lean/run/4573.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def test : IO Unit := do
let tmpFile := "4573.tmp"
let baseLines := #["foo", "bar", "foobar"]
let content := baseLines[0] ++ "\r\n" ++ baseLines[1] ++ "\n" ++ baseLines[2]
IO.FS.writeFile tmpFile content
let readLines ← IO.FS.lines tmpFile
IO.println <| baseLines == readLines
IO.FS.removeFile tmpFile

/-- info: true -/
#guard_msgs in
#eval test

0 comments on commit da9d44d

Please sign in to comment.