streams: DelimiterStream leaves delimiter bytes in the output when the delimiter spans more than two chunks

オープン 初心者向け
#7,386 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@helmipradita がすでに取り組んでいます。

2026年11月8日 から。

  • #7391 @helmipradita による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
deno, typescript

調査の方向性

DelimiterStreamの#handle()メソッドと、バッファリングされたチャンクが存在し、delimitedChunkEnd < 0となるissue記載の分岐から始めてください。複数のチャンクにまたがる部分的な区切り文字がどのようにトリミングされるかを追い、その後、issueの再現例を使って関連するstreamsのテストを実行してください。複数のチャンクにまたがる区切り文字について、空のチャンクを含め、discardとprefixが期待される出力を生成すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Describe the bug

With a multi-byte delimiter, DelimiterStream (discard and prefix) outputs part of the delimiter as data when a delimiter match starts two or more chunks before the chunk that completes it. An empty chunk in the middle of a two-byte delimiter is enough (["\r", "", "\n"] with "\r\n").

Steps to Reproduce

repro.ts:

import { DelimiterStream } from "jsr:@std/[email protected]/delimiter-stream";

const te = new TextEncoder(), td = new TextDecoder();
const run = async (
  chunks: string[],
  delim: string,
  disposition: "discard" | "prefix" | "suffix" = "discard",
) => {
  const out: string[] = [];
  for await (
    const c of ReadableStream.from(chunks.map((s) => te.encode(s)))
      .pipeThrough(new DelimiterStream(te.encode(delim), { disposition }))
  ) {
    out.push(td.decode(c));
  }
  return out;
};

console.log(await run(["xabcy"], "abc"));
console.log(await run(["xa", "b", "cy"], "abc"));
console.log(await run([..."one<END>two"], "<END>"));
console.log(await run(["\r", "", "\n"], "\r\n"));
console.log(await run(["xa", "b", "cy"], "abc", "prefix"));

deno run repro.ts

Expected behavior

[ "x", "y" ]
[ "x", "y" ]
[ "one", "two" ]
[ "", "" ]
[ "x", "abcy" ]

Actual behavior

[ "x", "y" ]
[ "xa", "y" ]
[ "one<EN", "two" ]
[ "\r", "" ]
[ "xa", "bcy" ]

In #handle(), the delimitedChunkEnd < 0 && bufs.length > 0 branch assumes the partial delimiter lies entirely in the last buffered chunk (last.byteLength + delimitedChunkEnd). When it spans several buffered chunks, that index goes negative and the earlier chunks are not trimmed.

Environment

  • OS: Ubuntu Linux x86_64
  • deno version: 2.9.8
  • std version: @std/streams 1.2.0, also main at f834d02 (same output)

Credit: https://ucsbplse.github.io/

主要言語
TypeScript
スター
3.6k
フォーク
713
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

denoland/std のほかの issue

denoland/std の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。