#800 correct handling parameter value empty array#801
Merged
iMacTia merged 1 commit intolostisland:masterfrom May 23, 2018
Merged
Conversation
lib/faraday/parameters.rb
Outdated
| buffer << "#{to_query.call(new_parent, val)}&" | ||
| end | ||
| return buffer.chop | ||
| elsif value.is_a?(Array) && value.size == 0 |
Member
There was a problem hiding this comment.
Perhaps the Array#empty? method is even clearer to read? For both the !value.empty? and for the value.empty? case.
Member
There was a problem hiding this comment.
I'd go a step further and merge this 2 branches:
...
elsif value.is_a?(Array)
return "#{parent}%5B%5D" if value.empty? # This is the only new line
buffer = ""
value.each_with_index do |val, i|
new_parent = "#{parent}%5B%5D"
buffer << "#{to_query.call(new_parent, val)}&"
end
return buffer.chop
...
Member
olleolleolle
left a comment
There was a problem hiding this comment.
Cool change, thanks for the contextual link to the other issue.
iMacTia
requested changes
May 23, 2018
lib/faraday/parameters.rb
Outdated
| buffer << "#{to_query.call(new_parent, val)}&" | ||
| end | ||
| return buffer.chop | ||
| elsif value.is_a?(Array) && value.size == 0 |
Member
There was a problem hiding this comment.
I'd go a step further and merge this 2 branches:
...
elsif value.is_a?(Array)
return "#{parent}%5B%5D" if value.empty? # This is the only new line
buffer = ""
value.each_with_index do |val, i|
new_parent = "#{parent}%5B%5D"
buffer << "#{to_query.call(new_parent, val)}&"
end
return buffer.chop
...8898a87 to
2602e3b
Compare
iMacTia
approved these changes
May 23, 2018
Member
|
Nice optimisation, looks good now. |
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.
Description
correct handling of parameters when value is an empty array
fix #800
Todos
List any remaining work that needs to be done, i.e:
Documentation (not sure where it should be documented)Additional Notes
Optional section
will fix JsonApiClient/json_api_client#278