Skip to content

fix: tighten JSON, JSONL, and SSE content type matching - #277

Merged
jbeckwith-oai merged 2 commits into
openai:mainfrom
fallintoplace:fix/jsonl-content-type-regex
Aug 10, 2026
Merged

fix: tighten JSON, JSONL, and SSE content type matching#277
jbeckwith-oai merged 2 commits into
openai:mainfrom
fallintoplace:fix/jsonl-content-type-regex

Conversation

@fallintoplace

@fallintoplace fallintoplace commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • require JSON and JSONL content types to match an exact, case-insensitive media type boundary
  • keep JSON and JSONL dispatch disjoint, including mixed-case application/jsonL
  • preserve supported x-ndjson, x-ldjson, jsonl, and x-jsonl media types with optional parameters and horizontal whitespace
  • apply the same case-insensitive boundary handling to Server-Sent Events
  • add matcher and end-to-end encode/decode regressions for valid, malformed, suffixed, and unrelated content types

Why

encode_content and decode_content select JSON, JSONL, and SSE behavior by content type. The previous JSONL regex matched unrelated values, while the JSON matcher could claim mixed-case JSONL before JSONL dispatch. Prefix-only matching also accepted invalid suffixes such as application/json-seq and text/event-streaming.

These cases could parse the wrong format, raise parser errors, or return the wrong decoded shape.

Fixes #276.

Test plan

  • mise exec ruby@4.0.6 -- ./scripts/test
  • mise exec ruby@4.0.6 -- bundle exec rake lint
  • mise exec ruby@4.0.6 -- bundle exec rake build:gem
  • GitHub Actions: 11 passed, 0 failed

@fallintoplace
fallintoplace marked this pull request as ready for review May 19, 2026 17:41
@fallintoplace
fallintoplace requested a review from a team as a code owner May 19, 2026 17:41
@jbeckwith-oai jbeckwith-oai added the generator Touches generated SDK files label Jul 16, 2026
@fallintoplace
fallintoplace force-pushed the fix/jsonl-content-type-regex branch from d89ace1 to 4f5db1e Compare July 16, 2026 23:29
@fallintoplace fallintoplace changed the title Tighten JSONL content type matching Fix false-positive JSONL content type matches Jul 16, 2026
@jbeckwith-oai
jbeckwith-oai force-pushed the fix/jsonl-content-type-regex branch from 4f5db1e to 5a7c815 Compare August 10, 2026 21:19
@jbeckwith-oai jbeckwith-oai changed the title Fix false-positive JSONL content type matches fix: tighten JSON, JSONL, and SSE content type matching Aug 10, 2026
@jbeckwith-oai
jbeckwith-oai force-pushed the fix/jsonl-content-type-regex branch from 5a7c815 to bf02d23 Compare August 10, 2026 21:34
@jbeckwith-oai
jbeckwith-oai added this pull request to the merge queue Aug 10, 2026
Merged via the queue into openai:main with commit 66359a0 Aug 10, 2026
12 checks passed
@openai-sdks openai-sdks Bot mentioned this pull request Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

generator Touches generated SDK files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSONL content type matcher accepts unrelated strings

2 participants