Skip to content

Commit

Permalink
fix(typescript): avoid parsing empty messageTerminators in JSON strea…
Browse files Browse the repository at this point in the history
…m case. (#5471)

* fix: avoid parsing empty messageTerminators in JSON stream case.

* add changelog.

* Update snapshots.
  • Loading branch information
eyw520 authored Dec 23, 2024
1 parent 7f5a1f4 commit 0883bb0
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 19 deletions.
4 changes: 4 additions & 0 deletions generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.44.5] - 2024-12-23

- Fix: Fix a bug where we attempt to parse an empty terminator when receiving streaming JSON responses.

## [0.44.4] - 2024-12-20

- Feat: Use specified defaults for pagination offset parameters during SDK generation.
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.44.4
0.44.5
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export class Stream<T> implements AsyncIterable<T> {
while ((terminatorIndex = buf.indexOf(this.messageTerminator)) >= 0) {
// Extract the line from the buffer
let line = buf.slice(0, terminatorIndex + 1);
buf = buf.slice(terminatorIndex + 1);
buf = buf.slice(terminatorIndex + this.messageTerminator.length);

// Skip empty lines
if (line.length === 0) {
if (!line.trim()) {
continue;
}

Expand Down Expand Up @@ -112,7 +112,7 @@ export class Stream<T> implements AsyncIterable<T> {
decoded += decoder.decode(chunk);
}
// Buffer is present in Node.js environment
else if (RUNTIME.type === "node" && typeof chunk != "undefined") {
else if (RUNTIME.type === "node" && typeof chunk !== "undefined") {
decoded += Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
}
return decoded;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0883bb0

Please sign in to comment.