fix #187: escape backslash in param encoding to fix newline in ViewId/state#192
Merged
seanhess merged 1 commit intoseanhess:mainfrom Mar 9, 2026
Merged
Conversation
seanhess#187) Previously, sanitizeParamText and desanitizeParamText did not escape the backslash character itself. This caused a collision: JSON's escape sequence for a newline character (the two chars '\' and 'n', written as \n in JSON) was indistinguishable from the param encoding's escape for a real newline. When a ViewId contained a list of Text with newline characters (e.g. Message ["\n"]), the list was JSON-encoded to ["\n"], and then desanitizeParamText would convert \n back into a real newline inside the JSON string, producing invalid JSON. The subsequent parse failure meant no handler matched the viewId, giving the error: "No Handler for Event viewId when view id or state data has new line character" Fix: escape backslash first in sanitizeParamText (\ → \\), and unescape it last in desanitizeParamText via a single-pass char-by-char decoder. This ensures that: - A real newline in a plain Text param is still encoded as \n (wire) and decoded back to a real newline. - A backslash in any param value (e.g. from JSON encoding) is encoded as \\ on the wire and decoded back to a single backslash, preserving JSON escape sequences intact. Added regression tests in EncodedSpec and ViewIdSpec covering the exact scenario from the issue report.
Owner
|
Great work! I tried to fix this quickly last week and got stuck. Thanks for doing this |
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.
Previously, sanitizeParamText and desanitizeParamText did not escape the backslash character itself. This caused a collision: JSON's escape sequence for a newline character (the two chars '' and 'n', written as \n in JSON) was indistinguishable from the param encoding's escape for a real newline.
When a ViewId contained a list of Text with newline characters (e.g. Message ["\n"]), the list was JSON-encoded to ["\n"], and then desanitizeParamText would convert \n back into a real newline inside the JSON string, producing invalid JSON. The subsequent parse failure meant no handler matched the viewId, giving the error:
"No Handler for Event viewId when view id or state data has new line character"
Fix: escape backslash first in sanitizeParamText (\ → \), and unescape it last in desanitizeParamText via a single-pass char-by-char decoder. This ensures that:
Added regression tests in EncodedSpec and ViewIdSpec covering the exact scenario from the issue report.
Fix #187