Skip to content

Allow empty array to be used as a params in get requests.#477

Merged
jnunemaker merged 1 commit intojnunemaker:masterfrom
dmitryrck:empty-array-get
Jun 12, 2016
Merged

Allow empty array to be used as a params in get requests.#477
jnunemaker merged 1 commit intojnunemaker:masterfrom
dmitryrck:empty-array-get

Conversation

@dmitryrck
Copy link
Contributor

Fixes #469

Now we have:

>> res = HTTParty.get('http://github.com', query: {fake_array: []})
# […]
>> res.request.last_uri.to_s
=> "https://github.com/?fake_array[]="

And:

>> res = HTTParty.get('http://github.com', query: {fake_array: [1]})
# […]
>> res.request.last_uri.to_s
=> "https://github.com/?fake_array[]=1"

Besides this fix I'd like to know what happens if you have something like this: HTTParty::Request.new(Net::HTTP::Get, 'http://google.com', query: { fake_array: [""] })

new_uri.query = query_string(new_uri)
possible_query_string = query_string(new_uri)

if possible_query_string != nil && possible_query_string != ""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiousity, what specifically made it so you need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well… I was doing baby steps and the change was required, but I double-checked and it is not required anymore :)

end

query_string_parts.reject!(&:empty?) unless query_string_parts == [""]
query_string_parts.reject! { |part|
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked locally and this isn't needed to make any specs pass. Do we need a new spec or is this extra as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird… I remember I needed this :/

Let me check :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jnunemaker thank you for the great review, it was necessary to change only HTTParty::HashConversions eventually :)

@jnunemaker jnunemaker merged commit 7af4154 into jnunemaker:master Jun 12, 2016
@DaftTrick
Copy link

In this PR you mention that change of behavior should be only for get method.
But this PR also changed working with POST request also. Is that designed that way or just a side-bug?

@dmitryrck
Copy link
Contributor Author

dmitryrck commented Aug 10, 2016

@DaftTrick I did all the tests based on GET, but I did not remember of seeing anything to mean that the behavior should be only to GET, so I think this code should work to POST too.

Why? Any problem with that?

P. S.: Sorry by the delay :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty array is ignored when passed as a param

3 participants