-
Notifications
You must be signed in to change notification settings - Fork 374
chore: update React on Rails and Shakapacker RC test matrix #740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0eb0d5c
d59d0c1
e26bec4
66a7caa
23cd58a
d0df4ab
0a1bd89
516ce28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,12 +11,48 @@ | |||||||
|
|
||||||||
| describe "RSC payload endpoint" do | ||||||||
| def parsed_chunks | ||||||||
| response.body.each_line.filter_map do |line| | ||||||||
| stripped = line.strip | ||||||||
| next if stripped.empty? | ||||||||
| body = response.body.b | ||||||||
| chunks = [] | ||||||||
|
|
||||||||
| JSON.parse(stripped) | ||||||||
| until body.empty? | ||||||||
| body = discard_blank_frame_lines(body) | ||||||||
| break if body.empty? | ||||||||
|
|
||||||||
| chunk, body = parse_length_prefixed_chunk(body) | ||||||||
| chunks << chunk | ||||||||
| end | ||||||||
|
|
||||||||
| chunks | ||||||||
| end | ||||||||
|
|
||||||||
| def discard_blank_frame_lines(body) | ||||||||
| body = body.byteslice(1..) || "".b while body.start_with?("\n") | ||||||||
| body | ||||||||
| end | ||||||||
|
|
||||||||
| def parse_length_prefixed_chunk(body) | ||||||||
| header_end = body.index("\n") | ||||||||
| raise "Malformed length-prefixed RSC payload: missing header newline" unless header_end | ||||||||
|
|
||||||||
| metadata_json, content_length_hex = body.byteslice(0, header_end).split("\t", 2) | ||||||||
| raise "Malformed length-prefixed RSC payload: missing tab separator" unless content_length_hex | ||||||||
|
|
||||||||
| content_start = header_end + 1 | ||||||||
| content_length = Integer(content_length_hex, 16) | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Or wrap with rescue: content_length = Integer(content_length_hex, 16)
rescue ArgumentError
raise "Malformed length-prefixed RSC payload: invalid hex length '#{content_length_hex}'" |
||||||||
| content = body.byteslice(content_start, content_length) | ||||||||
| raise "Malformed length-prefixed RSC payload: truncated content" unless content&.bytesize == content_length | ||||||||
|
|
||||||||
| [ | ||||||||
| parse_payload_metadata(metadata_json, content), | ||||||||
| body.byteslice(content_start + content_length, body.bytesize) || "".b | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| ] | ||||||||
| end | ||||||||
|
|
||||||||
| def parse_payload_metadata(metadata_json, content) | ||||||||
| metadata = JSON.parse(metadata_json.force_encoding(Encoding::UTF_8)) | ||||||||
| content.force_encoding(Encoding::UTF_8) | ||||||||
| metadata["html"] = metadata.delete("payloadType") == "object" ? JSON.parse(content) : content | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||
| metadata | ||||||||
| end | ||||||||
|
|
||||||||
| def expect_valid_rsc_payload | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
whilemodifier with an assignment on the same line is valid Ruby but uncommon enough to cause a double-take. An explicit loop block is easier to scan: