You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(streaming): SSE stream crashes on Unicode line separators (\u2028, \u2029, \x85) inside JSON payloads #45
Both Stream and AsyncStream fail with APIResponseValidationError whenever an SSE data: JSON payload contains unescaped Unicode line separators such as U+2028 (Line Separator), U+2029 (Paragraph Separator), or U+0085 (NEL) — characters that are valid inside RFC 8259 JSON strings and frequently appear in web, PDF, or JS content produced by agents.
Root Cause
Stream._iter_events() and AsyncStream._iter_events() (src/qca/common/_streaming.py) rely on httpx.Response.iter_lines() / aiter_lines(). httpx's LineDecoder splits using Python's str.splitlines(), which treats \u2028, \u2029, \x85, \x0b, \x0c, etc. as line breaks. Per the WHATWG Server-Sent Events specification, SSE lines may only be delimited by \r\n, \n, or \r.
Minimal Repro
Feeding data: {"content":[{"type":"text","text":"before\u2028after"}]}\n\n into Stream splits the JSON across two lines and raises APIResponseValidationError.
Proposed Fix
Decode SSE lines incrementally over iter_bytes() / aiter_bytes() using codecs.getincrementaldecoder, splitting strictly on \r\n, \r, or \n (preserving split CRLF across chunks, leading UTF-8 BOM handling, and _InterruptibleSyncBody sync cancellation).
Add sync and async regression tests covering \u2028, \u2029, \x85, control characters in comments, standalone \r, leading BOM, and 1-byte chunk boundaries.
I have a verified fix ready and will open a PR referencing this issue shortly.
Activity