-
Notifications
You must be signed in to change notification settings - Fork 63
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
[WIP] Add nested get query parameter expandation #84
Conversation
mustermann/mustermann.gemspec
Outdated
@@ -14,4 +14,6 @@ Gem::Specification.new do |s| | |||
s.files = `git ls-files`.split("\n") | |||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | |||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | |||
|
|||
s.add_dependency 'query_string_builder' |
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.
I can remove this dependency, it is my sample code
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.
First of all, please leave it dependent on your personal gem.
And this change doesn't seem to reach the essential part.
Could you elaborate?
inlin-ized and fixup this commit 1e5a12d |
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.
Did you read the source code?
Did you dig into the problem to understand the essence?
Your patch breaks expanding features.
By executing the following code, you can check the differences before and after applying your changes.
require 'mustermann'
pattern = Mustermann.new("/books/:id")
p pattern.expand(:append, id: "foo", bar: "&#?")
@@ -194,8 +194,7 @@ def slice(hash, keys) | |||
|
|||
def append(uri, values) | |||
return uri unless values and values.any? | |||
entries = values.map { |pair| pair.map { |e| @api_expander.escape(e, also_escape: /[\/\?#\&\=%]/) }.join(?=) } | |||
"#{ uri }#{ uri[??]??&:?? }#{ entries.join(?&) }" | |||
[uri, QueryStringBuilder.new(values).build].join('?') |
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.
I don't think QueryStringBuilder
is necessary. Recursive processing looks fine, but QueryStringBuilder
is really overkill.
@@ -194,8 +194,7 @@ def slice(hash, keys) | |||
|
|||
def append(uri, values) | |||
return uri unless values and values.any? | |||
entries = values.map { |pair| pair.map { |e| @api_expander.escape(e, also_escape: /[\/\?#\&\=%]/) }.join(?=) } | |||
"#{ uri }#{ uri[??]??&:?? }#{ entries.join(?&) }" |
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.
Why did you delete these lines? Your patch doesn't cover these feature.
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.
Fixed 2addf75
mustermann/spec/expander_spec.rb
Outdated
@@ -70,6 +70,9 @@ | |||
subject(:expander) { Mustermann::Expander.new('/:a', additional_values: :append) } | |||
example { expander.expand(a: ?a).should be == '/a' } | |||
example { expander.expand(a: ?a, b: ?b).should be == '/a?b=b' } | |||
example { expander.expand(a: ?a, b: [?b]).should be == '/a?b[]=b' } | |||
example { expander.expand(a: ?a, b: {c: ?c}).should be == '/a?b[c]=c' } | |||
example { expander.expand(a: ?a, b: {c: [1, 2]}).should be == '/a?b[c][]=1&b[c][]=2' } |
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.
The original test doesn't mention escape, but you need to add about it at least to add this change.
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.
Fixed f17ecc3
Thank you for reviews 😁I'll update this pull request soon. |
@iguchi1124 If you're going to include this fix in the 1.0.3 release, please write to that effect in the milestone issue. |
@@ -2,6 +2,7 @@ | |||
require 'mustermann/ast/expander' | |||
require 'mustermann/caster' | |||
require 'mustermann' | |||
require 'addressable/uri' |
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.
What is this?
I would not like to use the addressable
gem. Mustermann has not been depended on external gems.
Is there a clear reason to add this gem?
If so, why do not you add this to gemspec.
@iguchi1124 Hey, I'm going to release new version next week. So if you'd like to include this fix at the next version, please ping me. |
I'm creating this issue #61 examples in this pull request!
What do you think about this approach?