Skip to content
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

Adds URI#query_params method #8090

Merged

Conversation

rodrigopinto
Copy link
Contributor

This PR is for adding a URI#query_params which will generate a HTTP::Params instance parsed from the URI#query.

Example:

require "uri"

uri = URI.parse "http://foo.com?id=30&limit=5#time=1305298413"
uri.query_params # => HTTP::Params(@raw_params={"id" => ["30"], "limit" => ["5"]})

👉 it closes #8085

describe "#query_params" do
it do
uri = URI.parse("http://foo.com?id=30&limit=5#time=1305298413")
uri.query_params.should eq(HTTP::Params.parse("id=30&limit=5"))
Copy link
Member

Choose a reason for hiding this comment

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

Technically, the spec would be more reliant if the HTTP::Params instance was created from a spec. We're not testing Params.parse here, but still...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean? Something like:

expected_params = HTTP::Params.new({ "id" => ["30"], "limit" => ["5"]} )
uri.query_params.should eq(expected_params)

spec/std/uri_spec.cr Outdated Show resolved Hide resolved
@straight-shoota
Copy link
Member

@rodrigopinto Could you please squash the commits except the first one? I'd like to merge this as two commits, a spec refactor and a feature addition.

… of the query.

Using @asterite suggestions as it is more idiomatic.

Co-Authored-By: Ary Borenszweig <asterite@gmail.com>
@rodrigopinto
Copy link
Contributor Author

@straight-shoota it is done.

@straight-shoota straight-shoota merged commit d647ef2 into crystal-lang:master Sep 5, 2019
@straight-shoota
Copy link
Member

Thank you @rodrigopinto

@rodrigopinto rodrigopinto deleted the rp-add-query_params-to-uri branch September 5, 2019 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URI#query_params
3 participants