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

Template#expand to raise ArgumentError multivalued query param #284

Open
venki09 opened this issue Jan 3, 2018 · 5 comments
Open

Template#expand to raise ArgumentError multivalued query param #284

venki09 opened this issue Jan 3, 2018 · 5 comments

Comments

@venki09
Copy link

venki09 commented Jan 3, 2018

Currently the expand takes the mapping hash as input to construct the URI and from what I understand, doesn't look like it supports multivalued attribute? Example: I am trying to construct URI with the following mapping hash. Consider the Base path to be /myPath

{
service: ['a', 'b'],
id: 'abc'
}

and if I call the expand method as follows

Addressable::Template.new("/myPath{?params*}").expand(params: mapping_hash).to_s

which should be translated to /myPath?service=a&service=b&id=abc

Is it considered a valid enhancement to support or is there any other method which would allow to me to do what I need? I can issue a pull request if the change is valid. Thanks.

@dentarg
Copy link
Collaborator

dentarg commented Jan 4, 2018

Related to #282

@venki09
Copy link
Author

venki09 commented Feb 13, 2018

Ah nice that worked! thanks. This can be closed 👍

@sporkmonger
Copy link
Owner

Actually, I don't feel that this is a duplicate issue.

@sporkmonger
Copy link
Owner

However, I think the URI template spec doesn't define what behavior should be here. I think this should actually be an ArgumentError, TBQH.

@dentarg
Copy link
Collaborator

dentarg commented Jul 19, 2023

Currently fails like this when the mapping hash contains an array value

$ ruby -raddressable/template -e 'Addressable::Template.new("/myPath{?params*}").expand(params: { bar: ["bar"] })'
/Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/uri.rb:409:in `rescue in encode_component': Can't convert Array into String. (TypeError)

        raise TypeError, "Can't convert #{component.class} into String."
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/uri.rb:399:in `encode_component'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:802:in `block (2 levels) in transform_capture'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:797:in `each'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:797:in `map'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:797:in `block in transform_capture'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:756:in `each'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:756:in `inject'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:756:in `transform_capture'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:595:in `block in expand'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:594:in `gsub!'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:594:in `expand'
	from -e:1:in `<main>'
/Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/uri.rb:406:in `encode_component': undefined method `to_str' for ["bar"]:Array (NoMethodError)

          component = component.to_str
                               ^^^^^^^
Did you mean?  to_set
               to_s
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:802:in `block (2 levels) in transform_capture'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:797:in `each'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:797:in `map'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:797:in `block in transform_capture'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:756:in `each'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:756:in `inject'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:756:in `transform_capture'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:595:in `block in expand'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:594:in `gsub!'
	from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/addressable-2.8.4/lib/addressable/template.rb:594:in `expand'
	from -e:1:in `<main>'

@dentarg dentarg changed the title Enhancement request - Template.expand() method to support multivalued query param Template#expand to raise ArgumentError multivalued query param Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants