← 返回首页
Validate event and id fields in format_sse_event by raghavc · Pull Request #15867 · fastapi/fastapi · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Validate event and id fields in format_sse_event#15867

Draft
raghavc wants to merge 1 commit into
fastapi:masterfrom
raghavc:codex/fix-sse-format-validation
Draft

Validate event and id fields in format_sse_event#15867
raghavc wants to merge 1 commit into
fastapi:masterfrom
raghavc:codex/fix-sse-format-validation

Conversation

raghavc commented Jun 29, 2026

Copy link
Copy Markdown

Summary

ServerSentEvent already validates SSE event and id fields before rendering. This applies the same checks in the public format_sse_event() helper so callers cannot accidentally render multiline event or id values into extra SSE fields.

Discussion: #15648

Changes

  • Reuse the existing SSE validators at the start of format_sse_event().
  • Add regression tests for multiline event, multiline id, null-byte id, an injected data: line, and a valid event/id output.

Validation

  • pytest -q tests/test_sse.py
  • pytest -q tests/test_sse.py tests/test_tutorial/test_server_sent_events
  • ruff check fastapi/sse.py tests/test_sse.py
  • git diff --check

codspeed-hq Bot commented Jun 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks

Comparing raghavc:codex/fix-sse-format-validation (b50afab) with master (702fea8)

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Footer

© 2026 GitHub, Inc.