Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(io): readDelim returns wrong result if delim strides over chunks #877

Merged
merged 7 commits into from
May 14, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: createLPS bug
keroxp committed Apr 25, 2021
commit 82b327a6b19aa21678fd7f79e7c537b586a00ca8
2 changes: 1 addition & 1 deletion io/bufio.ts
Original file line number Diff line number Diff line change
@@ -621,7 +621,7 @@ function createLPS(pat: Uint8Array): Uint8Array {
lps[i] = 0;
i++;
} else {
prefixEnd = pat[prefixEnd - 1];
prefixEnd = lps[prefixEnd - 1];
}
}
return lps;
11 changes: 11 additions & 0 deletions io/bufio_test.ts
Original file line number Diff line number Diff line change
@@ -278,6 +278,17 @@ Deno.test("[io] readStringDelim bigger delim than buf size", async () => {
assertEquals(arr, exp);
});

Deno.test("[io] readStringDelim delim=1213", async () => {
const delim = "1213";
const exp = ["", "a", "bc", "def", "01", "012345678", "123456789", "", ""];
const str = exp.join(delim);
const arr: string[] = [];
for await (const v of readStringDelim(new StringReader(str), "1213")) {
arr.push(v);
}
assertEquals(arr, exp);
});

Deno.test("bufioPeek", async function () {
const decoder = new TextDecoder();
const p = new Uint8Array(10);