-
Notifications
You must be signed in to change notification settings - Fork 527
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
Fix unicode bug with "format_raw_parse_error" sample #1044
Fix unicode bug with "format_raw_parse_error" sample #1044
Conversation
%Absinthe.Phase.Error{ | ||
extra: %{}, | ||
locations: [%{column: 3, line: 1}], | ||
message: "Parsing failed at `;bbbbbbbb—`", |
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.
If we're thinking character-oriented and not byte oriented I would expect 10 characters. In practice this test will fail because the message will include a sample of ten bytes.
end | ||
|
||
@graphql ";" | ||
test "should provide sample of parsing failure on very short query strings" do |
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.
Not something we experienced, but something that occurred to me when I was thinking about the binary pattern match.
Great find! Seems like your proposed fix is a good one, let's see those tests turn green |
Awesome, updated with the fix @binaryseed ! |
Bit of a strange one, but I think I tracked it down, so I'm curious what folks think.
We ran into this issue after a user started sending some strange input our way that was (I suspect correctly) failing to parse. The weird part was we were seeing exceptions inside Absinthe.Plug as it attempted to JSON encode an error message to send back to the user, the exceptions looked something like this:
The bytes 226 (
0xE2
) and 128 (0x80
) are of interest here. If you remove them we have a valid string again:Which leads us to
Absinthe.Phase.Parse.format_raw_parse_error/1
where that message is generated.My hypothesis is this:
<<sample::binary-size(10), _::binary>>
grabbed the problematic character and the next ten bytes for the sample.—
==<<226, 128, 148>>
).<<226, 128>>
for example)In practice no exception occurred until the output of
Absinthe.Phase.Parse.format_raw_parse_error/1
made it to the JSON encoding step in the Absinthe.Plug pipeline, which was expecting a valid string. I think the tests here can still demonstrate the edge case though.Without knowing more, the most straightforward solution I can think of is to use
String.slice
which is unicode aware unless there's a reason we can't use it, but it did get the tests passing.The tests demonstrate two things. The first is a repro of the error I believe we're experiencing, the second is an edge case with very short, invalid documents that occurred to me while I was looking at the code.