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

Apply CGI.escape to non-array non-form values #722

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion rswag-specs/lib/rswag/specs/request_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def build_query_string_part(param, value, swagger_doc)
return "#{escaped_name}=" + value.to_a.flatten.map{|v| CGI.escape(v.to_s) }.join(separator)
end
else
return "#{name}=#{value}"
return "#{name}=#{CGI.escape(value)}"

Choose a reason for hiding this comment

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

CGI.escape(value.to_s)
The to_s was implicit before.

end
end

Expand Down
15 changes: 15 additions & 0 deletions rswag-specs/spec/rswag/specs/request_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ module Specs
expect(request[:path]).to eq('/blogs?q1=foo&q2=bar')
end

context 'when escaping is needed' do
before do
metadata[:operation][:parameters] = [
{ name: 'q1', in: :query, type: :string },
{ name: 'q2', in: :query, type: :string }
]
allow(example).to receive(:q1).and_return('order #123')
allow(example).to receive(:q2).and_return('last % ditch')
end

it 'builds the query string from example values with encoding' do
expect(request[:path]).to eq('/blogs?q1=foo&q2=bar')
end
end

context 'when `getter is defined`' do
before do
metadata[:operation][:parameters] << {
Expand Down