summaryrefslogtreecommitdiff
path: root/std/io/bufio.ts
diff options
context:
space:
mode:
authorIván Canales <kanales@users.noreply.github.com>2020-12-05 17:41:16 +0100
committerGitHub <noreply@github.com>2020-12-05 17:41:16 +0100
commitc10280214e5e15fb31b83368082916b9f25470f9 (patch)
treec0ca3b76a688c625629f23e8e77a48f1dbfbbef8 /std/io/bufio.ts
parent2d5c742cf608b2ce0c5a51fb80f34cfd8ffd2e83 (diff)
fix(std/bufio): Remove '\r' at the end of Windows lines (#8447)
Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
Diffstat (limited to 'std/io/bufio.ts')
-rw-r--r--std/io/bufio.ts10
1 files changed, 9 insertions, 1 deletions
diff --git a/std/io/bufio.ts b/std/io/bufio.ts
index 954fc5eee..df3ecb002 100644
--- a/std/io/bufio.ts
+++ b/std/io/bufio.ts
@@ -706,5 +706,13 @@ export async function* readStringDelim(
export async function* readLines(
reader: Reader,
): AsyncIterableIterator<string> {
- yield* readStringDelim(reader, "\n");
+ for await (let chunk of readStringDelim(reader, "\n")) {
+ // Finding a CR at the end of the line is evidence of a
+ // "\r\n" at the end of the line. The "\r" part should be
+ // removed too.
+ if (chunk.endsWith("\r")) {
+ chunk = chunk.slice(0, -1);
+ }
+ yield chunk;
+ }
}