HaxeFoundation / HaxeFoundation/haxe

FileInput.readLine() fails if last line is empty

Open
#5,418 3 comments 0 reactions 0 assignees View on GitHub
feature-filesystem Hacktoberfest
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

The following code fails on all sys targets with an EOF exception, but shouldn't because before invoking readLine the EOF status is tested.

``` haxe
class Test {
static function main() {
sys.io.File.saveContent("test.txt", "line1\nline2\n");
var is = sys.io.File.read("test.txt", false);
while (!is.eof()) {
trace(is.readLine());
}
is.close();
}
}
```

The example works if

``` haxe
sys.io.File.saveContent("test.txt", "line1\nline2\n");
```

is replaced by

``` haxe
sys.io.File.saveContent("test.txt", "line1\nline2");
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.