Allow response header value to contain a colon #722
Allow response header value to contain a colon #722
Conversation
HTTP response header field values are allowed to contain separators (which includes the colon) as long as they appear within quotes (http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2). This commit enables `Browser#response_headers` to handle a field value that contains a colon followed by a space (i.e., ": ") without breaking.
Thanks for looking into this, @rylwin! I think the best fix here may be to encode the response as JSON as we do with other methods, and decode on the Ruby side. This will simplify the code that needs to be maintained and brings this method in line with the others. Check out |
Thanks for the guidance, @mhoran! I've attempted a fix based on your suggestions and I'd like to discuss what I've found so far. I've updated Headers.cpp to use JsonSerializer, so when we
In ruby we still need to convert these items to a hash. For the last item in the example above, splitting on ":" causes the same error as before as the array splits into three parts (since there are two colons). I think working with headers differs from console messages because each item in the console messages is actually a QVariantMap. If the above is correct, then I don't think json serializing the Headers solves this problem. I think we need to add a bit of additional logic to split each header into key/value pairs that correctly handles the situation where the value contains an additional colon. I think we just need to decide whether this belongs somewhere in the cpp or ruby code. Thoughts? |
It looks like a few additional changes are required to make this possible. In With these changes in place, the signature of |
I see exactly what you're talking about. After looking at |
@mhoran I took another stab at it following your latest advice. Converting the headers property into a map made it really simple! |
@@ -273,4 +273,53 @@ | |||
end | |||
end | |||
end | |||
|
|||
describe '#response_headers' 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.
There are existing specs for response_headers
in spec/driver_spec.rb
. I think it would be worth just adding one more example where there's a colon, rather than duplicating the code for booting up a server.
@rylwin thanks for this! The C++ changes look awesome. I had one comment about the specs. If you're able to make that change, I think this will be ready to merge. |
Needed to rebuild the capybara binary to properly get this spec to fail when testing on master. When running with the patched binary (the one built from this branch) the previous version of this spec would fail, but it would actually pass against master when running with master's version of the binary. The spec now correctly reflects the failure condition (which is a colon followed by a space ": "); it fails when run on master with master's capybara binary and passes on this branch with the updated binary.
Thanks! I merged this into master as c0c9d70. |
HTTP response header field values are allowed to contain separators (which
includes the colon) as long as they appear within quotes
(http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2). This commit
enables
Browser#response_headers
to handle a field value that contains a colonfollowed by a space (i.e., ": ") without breaking.
Previously, a colon followed by a space would cause
#response_headers
to breakas
#split(": ")
would lead to an array with three parts whichHash[]
cannot handle.