Enhance message parsing to preserve newlines from empty data fields#104
Open
fa3eng wants to merge 1 commit intoAzure:mainfrom
Open
Enhance message parsing to preserve newlines from empty data fields#104fa3eng wants to merge 1 commit intoAzure:mainfrom
fa3eng wants to merge 1 commit intoAzure:mainfrom
Conversation
…nd update type for ReadableStream result. Add a test case to verify the new behavior.
Author
|
@microsoft-github-policy-service agree |
|
We just stumbled across that very same issue; very glad to see the issue is known, tracked, and a solution is here. Will this be released anytime soon? |
|
This issue should have been resolved by now. Any idea when this will be merged or what has to be done? @fa3eng |
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Preserve newlines from empty data fields in Server-Sent Events parsing
Issue:#50
Description
Problem
The current implementation of the Server-Sent Events (SSE) parser incorrectly handles empty data fields. When multiple consecutive empty
data:fields are encountered, the parser was not preserving the newline characters that should be added for each empty field, causing data loss and incorrect message formatting.According to the Server-Sent Events specification, each
data:field should append its value to the data buffer followed by a single U+000A LINE FEED (LF) character. This means that emptydata:fields should still contribute a newline character to the final message data.Solution
Modified the
getMessagesfunction insrc/parse.tsto properly handle empty data fields by ensuring that eachdata:field (including empty ones) contributes a newline character to the message data buffer.Key changes:
\n) after each data field value, regardless of whether the value is emptysrc/parse.spec.tsExample
Before (incorrect behavior):
Would result in:
data: "foo"(missing newlines from empty data fields)After (correct behavior):
Results in:
data: "\n\nfoo"(preserving newlines from empty data fields)Testing
should preserve newlines from empty data fieldsto verify the fixjasmine.jsonto point to the correct spec directoryImpact
This fix ensures full compliance with the Server-Sent Events specification and prevents data loss when processing SSE streams that contain empty data fields, which is a common pattern for formatting multi-line messages or creating visual spacing in SSE data.
Additional Information for the PR
Type of Change
Testing
Checklist